Find node by id in json tree
<p>I want to add the <code>children</code> array to node where <code>id = 52126f7d</code> (or another). How do I do it?</p>

<pre><code>var children = [
  { name: 'great-granchild3',
    id: '2a12a10h'
  },
  { name: 'great-granchild4',
    id: 'bpme7qw0'
  }
]

// json tree
var objects = {
  name: 'all objects',
  id:"2e6ca1c3",      
  children: [
     {
         name: 'child',
         id: "6c03cfbe",
         children: [                 
             { name: 'grandchild1',
               id: "2790f59c"
             },
             { name: 'grandchild2',
               id: "52126f7d"
             },
             { name: 'grandchild3',
               id: "b402f14b" 
             },
             {
               name: 'grandchild4',
               id: "6c03cff0",
               children: [
                 { name: 'great-grandchild1',
                   id: "ce90ffa6"
                 },
                 { name: 'great-grandchild2',
                   id: "52f95f28" 
                 }
              ]
            }
         ]
    },        
     {
       name: 'child2',
       id: "7693b310",
       children: [
          { name: 'grandchild5',
            id: "def86ecc"  
          },
          { name: 'grandchild6',
            id: "6224a8f8"
          }
       ]
    }
 ]
}
</code></pre>

<p>to end up with</p>

<pre><code>var objects = {
  name: 'all objects',
  id:"2e6ca1c3",      
  children: [
     {
         name: 'child',
         id: "6c03cfbe",
         children: [                 
             { name: 'grandchild1',
               id: "2790f59c"
             },
             { name: 'grandchild2',
               id: "52126f7d",
               children = [
                 { name: 'great-granchild3',
                   id: '2a12a10h'
                 },
                 { name: 'great-granchild4',
                   id: 'bpme7qw0'
                 }
               ]
             },
             { name: 'grandchild3',
               id: "b402f14b" 
             },
             {
               name: 'grandchild4',
               id: "6c03cff0",
               children: [
                 { name: 'great-grandchild1',
                   id: "ce90ffa6"
                 },
                 { name: 'great-grandchild2',
                   id: "52f95f28" 
                 }
              ]
            }
         ]
    },        
     {
       name: 'child2',
       id: "7693b310",
       children: [
          { name: 'grandchild5',
            id: "def86ecc"  
          },
          { name: 'grandchild6',
            id: "6224a8f8"
          }
       ]
    }
 ]
}
</code></pre>