title: D3 JSON data conversion
body: <p>I have this JSON data structure:</p>
  
  <pre><code>[
      { "dep": "d1", "name": "name1", "size": "size1" },
      { "dep": "d1", "name": "name2", "size": "size2" },
      { "dep": "d2", "name": "name1", "size": "size3" },
      { "dep": "d2", "name": "name1", "size": "size4" }
  ]
  </code></pre>
  
  <p>and I want to convert it to a nested structure like this:</p>
  
  <pre><code>{
      "name": "root",
      "children": [
          { "name": "d1",
              "children": [
                  { "dep": "d1", "name": "name1", "size": "size1" },
                  { "dep": "d1", "name": "name2", "size": "size2" }
              ]
          },
          { "name": "d2",
              "children": [
                  { "dep": "d2", "name": "name1", "size": "size3" },
                  { "dep": "d2", "name": "name2", "size": "size4" }
              ]
          }
      ]
  }
  </code></pre>
  
  <p>... and further using it to make the <a href="http://bl.ocks.org/mbostock/4063550">Reingold–Tilford Tree</a>. Can anyone point me to the right direction, I'm pretty new to D3!</p>