title: How to Iterate the JSON object and add a key value pair object dynamically using its hierarchy level in Javascript?
body: <p>I want this JSON to be iterated and add a key value pair with its level.</p>
  
  <p><strong>For example:</strong></p>
  
  <p>The first level hierarchy should be level 0 and second level should be level 1, and so on.</p>
  
  <pre><code>var json = [{
    "name": "parent 1",
    "children": [
      {
        "name": "child 1",
        "children": [
              {
              "name": "child 11"
              }
          ]
      },
      {
        "name": "child 2"
      }
    ]
  }];
  </code></pre>
  
  <p><strong>Expected json:</strong></p>
  
  <pre><code>var json = [
  {
    "name": "parent 1",
    "level": "0",
    "children": [
      {
        "name": "child 1",
        "level": "1",
        "children": [
              {
              "name": "child 11",
              "level": "2"
              }
          ]
      },
      {
        "name": "child 2",
        "level": "1"
      }
    ]
  }];
  </code></pre>