title: How to use a recursive filter all single JSON data?
body: <p>I want all of the individual nodes in the tree all merged into its parent, but if its child nodes contain two or more child nodes, without any change。</p>
  
  <p>Here is my data model example: </p>
  
  <pre><code>[{
          name: "HOME",
          value: [{//Only node merged into the parent level
              name: "HOME",
              value: [{//Only node merged into the parent level
                  name: "HOME",
                  id: '1000'
              }] 
          }]
      }, {
          name: "ARTICLE",
          value: [{
              name: "ARTICLE",
              value: [{
                  name: "ARTICLE TYPE 1",
                  id: '2001'
              },{
                  name: "ARTICLE TYPE 2",
                  id: '2002'
              }] 
          },{
              name: "ARTICLE",
              value: [{//Only node merged into the parent level
                  name: "ARTICLE TYPE 3",
                  id: '2003'
              }] 
          }]
      }]
  </code></pre>
  
  <p>I want to filter the data get like this：</p>
  
  <pre><code>    [{
          name: "HOME",
          id: 1000
      }, {
          name: "ARTICLE",
          value: [{
              name: "ARTICLE",
              value: [{
                  name: "ARTICLE TYPE 1",
                  id: '2001'
              },{
                  name: "ARTICLE TYPE 2",
                  id: '2002'
              }] 
          },{
              name: "ARTICLE TYPE 3",
              id: '2003'
          }]
      }]
  </code></pre>
  
  <p>//Update 1:
  This is the idea, but now there is a problem, find the node can not fall back to the original node, you can only modify the current parent node:</p>
  
  <pre><code>function filter(data){
      for(var i = 0; i &lt; data.length; i++){
          if( !data[i].value ) continue;
  
          //Check whether there are child nodes "value" is because it contains a "value" does not exist "id",
          //you must enter a recursive make the following checks
          if( data[i].value.length === 1 &amp;&amp; !data[i].value[0].value ) {
              data[i].id = data[i].value[0].id;
              delete data[i].value;
              continue;
          }
          filter( data[i].value );
      }
      return data;
  }
  </code></pre>
  
  <p>I am now directly modify the original object, I do not know whether it is reasonable to do so.</p>
  
  <p>//Update 2:
  My final wording is like this, the resulting output appears to be correct, but are not sure the logic is correct, and it looks very ugly, or do not know whether there is a better solution?</p>
  
  <pre><code>function filter(data, parent){
      for(var i = 0; i &lt; data.length; i++){
          if( data[i].value ) filter( data[i].value, data[i] );
  
          if( parent &amp;&amp; data.length === 1 &amp;&amp; !data[i].value ) {
              parent.id = data[i].id;
              delete parent.value;
          }
      }
      return data;
  }
  </code></pre>