I am trying to rename key names in a json object.I can rename at the top level, but unable to rename if the key present inside another object or if it present in a List Object.
This is what i have tried so far.
try {
jsonObject.put(value, jsonObject.remove(key));
LOG.trace("Renaming Field {} with Field {}", key, value);
} catch (JSONException e) {
throw new RuntimeException(e);
}
Here is an Example Object.
{
"id": 123,
"contactInformation": {
"contact": {
"email": "[email protected]",
}
},
"supportingCustomer": [
{
"supportingCustomerName": "JOHN"
},
{
"supportingCustomerName": "JOHN"
}
]
}
Here I can rename Id, but having difficulty renaming supportingCustomerName and also contactInformation.contact.email using org.json.JSONObject ? Or is there any other library, i can use to rename keys.Any Help would be appreciated?
My JSON And key are dynamic not fixated.
str = str.replace("supportingCustomerName","Example"); System.out.println(str);on the string of thejsonObject.