title: JSON tree to parent-link structure
body: <p>I have a JSON tree structure:</p>
  
  <pre><code>nodes = 
  [
  {
      "name": "user1",
      "children": [
          {
              "name": "user2"
          },
          {
              "name": "user3",
              "children": [
                  {
                      "name": "user4"
                  }
              ]
          },
          {
              "name": "user5"
          }
      ]
  }
  ]
  </code></pre>
  
  <p>that I would like to convert to a parent-link structure:</p>
  
  <pre><code>[{"name": "user1","parent": "null"},
   {"name": "user2","parent": "user1"},
   {"name": "user3","parent": "user1"},
   {"name": "user4","parent": "user3"},
   {"name": "user5","parent": "user1"}]
  </code></pre>
  
  <p>I have tried to traverse the tree recursively but without success accessing the parent object:</p>
  
  <pre><code>rebuild(nodes,parentLink);
  
  function parentlink(key,value) {
      var obj = { name: value , parent: ??? };
      if (key == "name"){
          nodes.push(obj);
      }
  }
  
  function rebuild(o,func) {
      for (i in o) {
          func.apply(this,[i,o[i]])
        if (typeof(o[i])=="object") {
          traverse(o[i],func,nodes);
        }
      }
  }
  </code></pre>
  
  <p>In developer tools I can see the parent objects for each child, but I don't know how to access them. What should I do to add the parent to each user?</p>