title: updating json object using java
body: <p>Let i've an <code>JSON</code> Object like as shown below</p>
  
  <pre><code>{"Name":"Manu","Age":"25","Address":""}
  </code></pre>
  
  <p><strong>Updation</strong> </p>
  
  <p>Read the json object and need to update the address field like as given below</p>
  
  <pre><code> {"Name":"Manu","Age":"25","Address":"XXXX"}
  </code></pre>
  
  <p>can anyone please tell me how to update the Address details in the <code>JSON</code> using <code>java</code></p>
  
  <p>My code</p>
  
  <pre><code>JSONObject rec = new JSONObject(data);
  String name = rec.getString("Name");
  String age  = rec.getString("Age"); 
  String add  = rec.getString("Address"); 
  </code></pre>
  
  <p>now how to add some information to the address field</p>
  
  <p><strong>Update 1</strong></p>
  
  <pre><code>String jsonstring="{Name:Manu,Age:25,Address:''}";
  JSONObject object=new JSONObject(jsonstring);
  JSONObject childobject=object.getJSONObject("Address");
  
  JSONObject modifiedjson=new JSONObject();
  modifiedjson.put("type",childobject.get("type"));
  modifiedjson.put("value","newvalue"); 
  </code></pre>
  
  <p><strong>Exception</strong> </p>
  
  <pre><code>Exception in thread "main" org.json.JSONException: JSONObject["Address"] is not a JSONObject.
      at org.json.JSONObject.getJSONObject(JSONObject.java:557)
      at kotouch.Sample.main(Sample.java:59)
  Java Result: 1
  </code></pre>