title: Convert json to other json structure
body: <p>I have an array of objects with this structure:</p>
  
  <pre><code>const treeData = [
    { 0: ["0-0", "0-1"] },
    { 1: ["1-0", "1-1"] }
  ]
  </code></pre>
  
  <p>It could be deeper but array data would be always json or strings</p>
  
  <pre><code>const treeData = [
    { 0: ["0-0", "0-1"] },
    { 1: ["1-0", "1-1"] },
      2,
      3
  ]
  </code></pre>
  
  <p>I would like to get something like this:</p>
  
  <pre><code>const treeDataResult = [
    {
      label: "0",
      value: "0",
      children: [
        {
          label: "0-0",
          value: "0-0"
        },
        {
          label: "0-1",
          value: "0-1",
        }
      ]
    },
    {
      label: "1",
      value: "1",
      children: [
        {
          label: "1-0",
          value: "1-0",
        },
        {
          label: "1-1",
          value: "1-1",
        }
      ]
    },
    { 
      label: "2",
      value: "2"
    },
    { 
      label: "3",
      value: "3"
    }
  ]
  </code></pre>
  
  <p>My code right now is this:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const treeData = [
        { "0": ["0-0", "0-1"] },
        { "1" : ["1-0", "1-1"] }
      ];
  
  const convertNode = (parentNode) =&gt;
    parentNode.map(
      childnode =&gt; {
        if (typeof(childNode) === 'string')
          return {
            label: childNode,
            value: childNode
          }
        else
          return
        childNode.map((key, val) =&gt;
          ({
            label: key,
            value: key,
            children: convertNode(val)
          })
        )
      }
    )
  
  var treeDataResult = convertNode(treeData);
  console.log(treeDataResult);</code></pre>
  </div>
  </div>
  </p>