title: Hierarchical json from flat with parent ID
body: <p><a href="http://jsfiddle.net/eYgGK/" rel="nofollow noreferrer">http://jsfiddle.net/eYgGK/</a></p>
  <p>I stole this script from a different post:</p>
  <pre><code>function convertToHierarchy() {
    var arry = [
      { &quot;Id&quot;: &quot;1&quot;, &quot;Name&quot;: &quot;abc&quot;, &quot;Parent&quot;: &quot;&quot;, &quot;attr&quot;: &quot;abc&quot; },
      { &quot;Id&quot;: &quot;2&quot;, &quot;Name&quot;: &quot;abc&quot;, &quot;Parent&quot;: &quot;1&quot;, &quot;attr&quot;: &quot;abc&quot; },
      { &quot;Id&quot;: &quot;3&quot;, &quot;Name&quot;: &quot;abc&quot;, &quot;Parent&quot;: &quot;2&quot;, &quot;attr&quot;: &quot;abc&quot; },
      { &quot;Id&quot;: &quot;4&quot;, &quot;Name&quot;: &quot;abc&quot;, &quot;Parent&quot;: &quot;2&quot;, &quot;attr&quot;: &quot;abc&quot; }
    ];
    var nodeObjects = createStructure(arry);
    for (var i = nodeObjects.length - 1; i &gt;= 0; i--) {
      var currentNode = nodeObjects[i];
      if (currentNode.value.Parent === &quot;&quot;) {
        continue;
      }
      var parent = getParent(currentNode, nodeObjects);
  
      if (parent === null) {
        continue;
      }
  
      parent.children.push(currentNode);
      nodeObjects.splice(i, 1);
    }
    console.dir(nodeObjects);
    return nodeObjects;
  }
  
  function createStructure(nodes) {
    var objects = [];
  
    for (var i = 0; i &lt; nodes.length; i++) {
      objects.push({
        value: nodes[i],
        children: []
      });
    }
  
    return objects;
  
  }
  
  function getParent(child, nodes) {
    var parent = null;
  
    for (var i = 0; i &lt; nodes.length; i++) {
      if (nodes[i].value.Id === child.value.Parent) {
        return nodes[i];
      }
    }
  
    return parent;
  }
  </code></pre>
  <p>This script produces:</p>
  <pre><code>[{
      &quot;value&quot;: {
          &quot;Id&quot;: &quot;1&quot;,
          &quot;Name&quot;: &quot;abc&quot;,
          &quot;Parent&quot;: &quot;&quot;,
          &quot;attr&quot;: &quot;abc&quot;
      },
      &quot;children&quot;: [{
          &quot;value&quot;: {
              &quot;Id&quot;: &quot;2&quot;,
              &quot;Name&quot;: &quot;abc&quot;,
              &quot;Parent&quot;: &quot;1&quot;,
              &quot;attr&quot;: &quot;abc&quot;
          },
          &quot;children&quot;: [{
              &quot;value&quot;: {
                  &quot;Id&quot;: &quot;4&quot;,
                  &quot;Name&quot;: &quot;abc&quot;,
                  &quot;Parent&quot;: &quot;2&quot;,
                  &quot;attr&quot;: &quot;abc&quot;
              },
              &quot;children&quot;: []
          }, {
              &quot;value&quot;: {
                  &quot;Id&quot;: &quot;3&quot;,
                  &quot;Name&quot;: &quot;abc&quot;,
                  &quot;Parent&quot;: &quot;2&quot;,
                  &quot;attr&quot;: &quot;abc&quot;
              },
              &quot;children&quot;: []
          }]
      }]
  }]
  </code></pre>
  <p>What I'm looking for is:</p>
  <pre><code>[{
      &quot;Id&quot;: &quot;1&quot;,
      &quot;Name&quot;: &quot;abc&quot;,
      &quot;Parent&quot;: &quot;&quot;,
      &quot;attr&quot;: &quot;abc&quot;,
      &quot;children&quot;: [{
  
          &quot;Id&quot;: &quot;2&quot;,
          &quot;Name&quot;: &quot;abc&quot;,
          &quot;Parent&quot;: &quot;1&quot;,
          &quot;attr&quot;: &quot;abc&quot;,
          &quot;children&quot;: [{
  
              &quot;Id&quot;: &quot;4&quot;,
              &quot;Name&quot;: &quot;abc&quot;,
              &quot;Parent&quot;: &quot;2&quot;,
              &quot;attr&quot;: &quot;abc&quot;
          }, {
  
              &quot;Id&quot;: &quot;3&quot;,
              &quot;Name&quot;: &quot;abc&quot;,
              &quot;Parent&quot;: &quot;2&quot;,
              &quot;attr&quot;: &quot;abc&quot;
             
          }]
      }]
  }]
  </code></pre>
  <p>I need to get rid of &quot;value&quot; wrapper primarily, and the empty child node secondarily.
  I know I can write a clean up script, but that would be less than best practice.
  Would be great if someone knows how to fix, or suggest a different script!</p>
  <p>Thanks</p>