title: How to change structure of nested/recursive JSON
body: <p>I have a JSON Array which looks like this:</p>
  
  <pre><code>[
      {id:1, name:"Name1", data1:"x", data2:"x", children:
          [
              {id:2, name:"Name2", data1:"x", data2:"x"},
              {id:3, name:"Name3", data1:"x", data2:"x", children:[...]},
          ]
      },
      {text: ..... },
      ...
  ]
  </code></pre>
  
  <p>And I need to do a similar JSON Array. I just need every object to have <code>text</code> attribute which equals the <code>name</code>. And <code>data</code> attribute which is a JSON of old attributes except <code>children</code>.</p>
  
  <p>It would not be a big problem in Python (it needs some recursion probably) but I can't figure out how to make it work in <code>JavaScript</code></p>
  
  <p>So this would look like:</p>
  
  <pre><code>[
      {text:"Name1", data:{id:1, name:"Name1", data1:"x", data2:"x"}, children:
          [
              {text:"Name2", data:{id:2, name:"Name2", data1:"x", data2:"x"}},
              {text:"Name3", data:{id:3, name:"Name3", data1:"x", data2:"x"}, children:[...]},
          ]
      },
      {id:4 ..... },
      ...
  ]
  </code></pre>