I am trying to create nested json object using org.json.simple.JSONObject
. why does jsonobject change order?
Expected output:
{
"id":"14",
"email":"xxx@gmail.com",
"Company":{
"address":"milton street",
"postal code":"cincinnati",
"name":"abc"
}
}
Current Output:
{
"Company":{
"address":"milton street",
"postal code":"cincinnati",
"name":"abc"
},
"id":"14",
"email":"xxx@gmail.com"
}
Here is my code:
JSONObject First = new JSONObject();
First.put("id", "14");
First.put("email", "xxx@gmail.com");
JSONObject companydetails = new JSONObject();
companydetails.put("name", "abc");
companydetails.put("address", "milton street");
companydetails.put("postal code", "cincinnati");
First.put("Company",companydetails);
System.out.println(First.toString());