convert json to xml without changing the order of parameters in python
Question: I'm using Json2xml module for converting json format to xml format. But, while
converting it changes the order of the parameters. How do I convert without
changing the order of parameters? Here's my python code.

    
    
    from json2xml.json2xml import Json2xml
    
    data = Json2xml.fromjsonfile('example.json').data
    data_object = Json2xml(data)
    xml_output = data_object.json2xml()
    print xml_output
    

example.json

    
    
    {
        "action": {
          "param1": "aaa",
          "param2": "bbb"
        }
    }
    

The output is

    
    
    <action>
    <param2>bbb</param2>
    <param1>aaa</param1>
    </action>
    

Is there a way to convert json to xml without changing the order of
parameters?


Answer: Try using an `OrderedDict`:

    
    
    from collections import OrderedDict
    from json2xml.json2xml import Json2xml
    
    data = Json2xml.fromjsonfile('example.json').data
    data = OrderedDict(data)
    data_object = Json2xml(data)
    xml_output = data_object.json2xml()
    print xml_output
    

