How to Convert JSON to XML in java whilst keeping same order of XML attributes as in JSON

I have the below function

    public String convertToXml(String json) throws JSONException {
        JSONObject jsonObject = new JSONObject(json);
        String xml = XML.toString(jsonObject);
        return xml;

that is converting JSON String to XML. However, some attributes are being swapped from their position for example

{"isbn": "123-456-222",  
      "lastname": "Doe",
      "firstname": "Jane"
      "lastname": "Smith",
      "firstname": "Jane"
  "title": "The Ultimate Database Study Guide",  
  "category": ["Non-Fiction", "Technology"]


<title>The Ultimate Database Study Guide</title>

How can I make sure that the XML has the same order as JSON? I used org.json.XML from



I downloaded the Official JSON-java repository and changed constructor from

public JSONObject() { = new HashMap();


public JSONObject() { = new LinkedHashMap();

then i compiled it again to .jar file and include it to my project.