title: Recursively traverse through json adding a name/value pair to each Object
body: <p>My json looks something like this but a lot more nodes/children:</p>
  
  <pre><code>[{"text":"Millions", "children":[
  {"text":"Dinosaur", "children":[{"text":"Stego"}]}, 
  {"text":"Dinosaur", "children": [{"text":"T-REX"}]}]}]
  </code></pre>
  
  <p>I'm trying to recursively go through all the children and add a name/value ("checked": false) pair to the json so that it would now look like:</p>
  
  <pre><code>[{"text":"Millions", "checked": false, "children":[
  {"text":"Dinosaur", "checked": false, "children":[{"text":"Stego", "checked": false,}]}, 
  {"text":"Dinosaur", "checked": false, "children": [{"text":"T-REX", "checked": false,}]}]}]
  </code></pre>
  
  <p>What I've come up with so far is:</p>
  
  <pre><code>JSONArray jArrayChecked = new JSONArray();
  
  //This traverses through the nodes
  public void addChecked(JSONArray ja){
    for(JSONObject jo : ja){
      if(jo.has("children")
        addChecked(jo.get("children");
  
      jo.put("checked", false);
      //This part is incorrect
      jArrayChecked.put(jo);
    }
  }
  </code></pre>
  
  <p>How can I properly add the name/value pairs to each node while keeping the node structure intact?</p>