I use json-simple
and want to have pretty-print for debugging purposes.
Here is a very relavant SO question: Pretty-Print JSON in Java
However the answer in the given thread, not only fixes the indentation but also changes the order of the items to [a ... z] using the string order of the keys.
Is there any way to fix the indentation without changing the order of the items in my JSONObject?
Example:
JSONObject myJSon = new JSONObject();
myJSon.put("zzz", 1);
myJSon.put("aaa", 1);
Gson gson = new GsonBuilder().setPrettyPrinting().create();
System.out.println( gson.toJson(myJSon) );
Output:
{
"aaa": 1,
"zzz": 1
}
Desired output:
{
"zzz": 1,
"aaa": 1
}
Edit: I'm using: org.json.simple.JSONObject