title: Dynamic nested ul\li list from json data using Javascript
body: <p>I need to create a dynamic nested ul\li list from json array.</p>
  
  <p><strong>NOTE!</strong> I can do that transformation my self using jQuery, but in this case i need to work with a string, since it's node.js and i don't have access to DOM.</p>
  
  <p>Also the array can have different depth.</p>
  
  <p>This is json data i work with and how it should look after transformation.</p>
  
  <pre><code>var data = [{"id": "1", "name": "name_1", "parent_id": "0", "depth": "0"},
          {"id": "2", "name": "name_2", "parent_id": "0", "depth": "0"},
          {"id": "3", "name": "name_3", "parent_id": "1", "depth": "1"},
          {"id": "4", "name": "name_4", "parent_id": "3", "depth": "2"}];
  
  &lt;ul&gt;
    &lt;li&gt;name_1&lt;/li&gt; //depth 0
    &lt;li&gt;name_2  //depth 0
      &lt;ul&gt;
        &lt;li&gt;name_3 //depth 1
          &lt;ul&gt;
            &lt;li&gt;name_3&lt;/li&gt; //depth 2
          &lt;/ul&gt;
        &lt;/li&gt;
      &lt;/ul&gt;
    &lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>I hope this is clear. If not please ask any questions in the comment.
  Thank you in advanced.</p>