0

Anyone know how to convert from json to xml but keeping the data in the same order (without ordering them). I tried Json2xml, dicttoxml and dict2xml but all of them are ordering the data. Please I need help, thank you! For example: from dict2xml import dict2xml

data = {
  'b': 1,
  'a': 7
}

print (dict2xml(data, wrap="all", indent="  "))

Is giving an output:

<all>
  <a>7</a>
  <b>1</b>
</all>
HElooo
  • 23
  • 4
  • Can you give an example ? The [official example](https://github.com/delfick/python-dict2xml) keeps the order. Btw. what's your Python version ? – Maurice Meyer Dec 08 '20 at 12:14
  • I updated the question to include example, py version is 3.5.2 – HElooo Dec 08 '20 at 12:20
  • Dictionaries do not preserve order in Py<3.7. You need to convert them into a [OrderedDict](https://docs.python.org/3.5/library/collections.html#ordereddict-examples-and-recipes) – Maurice Meyer Dec 08 '20 at 12:28
  • @MauriceMeyer the point is that I dont want to save them in order. I just want them to be in the same order that I eneterd them – HElooo Dec 08 '20 at 12:30
  • Easiest would be to switch to Python3.6, to [preserve insert order](https://stackoverflow.com/questions/39980323/are-dictionaries-ordered-in-python-3-6) – Maurice Meyer Dec 08 '20 at 12:39

0 Answers0