Search code examples
javajson4gl

How to add json object into another json object at the same level?


suppose that i have json object

"body" : -{
    "clinic" : -{
         "address" : -{
         "city" : Costa Mesa,
         "state" : CA      
          }

I want to add 'doctor' json object with its children as the same level as clinic in the given example.


Solution

  • You just need to get the JSONObject of the body and put the doctor

     ((JSONObject) yourJson.get("body")).put("doctor", doctorJSON);