question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Only OrderedDicts are returned

See original GitHub issue

This may just be a documentation issue, but when I run: (Python 2.7 OS X)

foo = xmltodict.parse("""<?xml version="1.0" ?>
        <person>
          <name>john</name>
          <age>20</age>
        </person>""")

    print foo

I get:

Output: OrderedDict([(u’person’, OrderedDict([(u’name’, u’john’), (u’age’, u’20’)]))])

In a nested XML document, this is making hard for me to turn this into JSON

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Reactions:2
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

45reactions
vstoykovcommented, Nov 17, 2015

@scharfmn I just found that you can use:

foo = xmltodict.parse(xml_string, dict_constructor=dict)
4reactions
vstoykovcommented, Jul 24, 2018

In future if Python 3.7+ is detected then instead of collections.OrderedDict the normal dict can be used by default because it will preserve the order by default.

Read more comments on GitHub >

github_iconTop Results From Across the Web

OrderedDict vs dict in Python: The Right Tool for the Job
Iterating Over an OrderedDict. Just like with regular dictionaries, you can iterate through an OrderedDict object using several tools and techniques. You can ......
Read more >
python - Does ordered dict return keys in order too?
Yes, OrderedDict will return the keys in order. It is worth mentioning, however, that the keys views compare order insensitive which is ...
Read more >
OrderedDict in Python
An OrderedDict is a dictionary subclass that remembers the order that keys were first inserted. The only difference between dict() and ...
Read more >
collections — Container datatypes
Returns a new ChainMap containing a new map followed by all of the maps in the current instance. If m is specified, it...
Read more >
Python OrderedDict
When we iterate over an OrderedDict, items are returned in the order they were inserted. A regular dictionary doesn't track the insertion order....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found