title: Create JSON from nested set model javascript
body: <p>I have this data structure that show the depth of each node in the nested tree:</p>
  
  <pre><code>[
    {
      "name": "ELECTRONICS",
      "depth": 0
    },
    {
      "name": "TELEVISIONS",
      "depth": 1
    },
    {
      "name": "TUBE",
      "depth": 2
    },
    {
      "name": "PLASMA",
      "depth": 2
    },
    {
      "name": "GAME CONSOLES",
      "depth": 1
    },
    {
      "name": "MP3 PLAYERS",
      "depth": 1
    },
    {
      "name": "FLASH",
      "depth": 2
    }]
  </code></pre>
  
  <p>I would like to transform the previews data with JavaScript / node.js / Angular into a hierarchical JSON like this:</p>
  
  <pre><code>[{
      "name": "ELECTRONICS",
      "children": [
        {
          "name": "TELEVISIONS",
          "children": [
            {
              "name": "TUBE"
            },
            {
              "name": "PLASMA"
            }]
       }, 
       {
          "name": "GAME CONSOLES"
       }, 
       {
          "name": "MP3 PLAYERS",
          "children": [
            {
              "name": "FLASH"
           }]
      }]
  }]
  </code></pre>