How to change json object name (key)?

Just a quick question:

If I have a json object that contains a "key / value" like:



and I want to change parts of the name to something else, what should I do? I don't want to delete and do it again.


source to share

2 answers

Correct and compact implementation, given that jsonObject

- this is the json object you are accessing and this is an instance jsonObject


jsonObject.put("new name", jsonObject.remove("name"));




Create a new object with a new value

new JSONObject(jsonobject.toString().replace("\"name\":","\"newvalue\":");)




All Articles