Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change json object name (key)?

Tags:

java

android

Just a quick question:

If I have a json object which contains "key/value"s like this:

"name":"value"

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

like image 717
SaDeGH_F Avatar asked Dec 15 '22 19:12

SaDeGH_F


1 Answers

Proper and compact implementation, given that jsonObject is the json object you are referring to and it is an instance of JSONObject:

jsonObject.put("new name", jsonObject.remove("name"));
like image 168
njzk2 Avatar answered Feb 12 '23 10:02

njzk2