title: Segregate and arrange data in specific format in Angular?
body: <p>Hi I am developing Angular 5 application. I am trying to arrange data in specific format. I have json data. I want to convert it to specific format. </p>
  
  <p>Below is the specific format.</p>
  
  <pre><code> this.nodes = [
  
        {
          name: 'root1',
          children: [
            { name: 'child1' }
          ]
        },
  
        {
          name: 'root2',
          hasChildren: true
        },
  
        {
          name: 'root3'
        }
  
      ];
  </code></pre>
  
  <p>Below is my data.</p>
  
  <pre><code>   {  
         "userid":"e75792f8-cfea-460e-aca2-07a778c92a7c",
         "tenantid":"00000000-0000-0000-0000-000000000000",
         "username":"karthik",
         "emailaddress":"john@krsars.onmicrosoft.com",
         "isallowed":false,
         "userroles":[  
            {  
               "userroleid":"b81e63d1-09da-4aa0-af69-0f086ddb20b4",
               "userid":"e75792f8-cfea-460e-aca2-07a778c92a7c",
               "roleid":"85d2f668-f523-4b64-b177-b1a78db74234",
               "tenantappid":1,
               "validfrom":"2018-01-24T00:00:00",
               "validto":"2018-01-24T00:00:00",
               "isactive":true,
            }
         ]
      }
  </code></pre>
  
  <p>From the above data, I am trying to convert. From the above data each key/value pair I am converting it to format above given, For example, "userid":"e75792f8-cfea-460e-aca2-07a778c92a7c" I want to make it as </p>
  
  <pre><code> {
          name: 'userid',
           children: [
             { name: 'e75792f8-cfea-460e-aca2-07a778c92a7c' }
           ]
   }
  </code></pre>
  
  <p>So below I is my code.</p>
  
  <pre><code> for (let key in results) {
       if(results[key] instanceof Array){
          this.nodes+=
            name:key,
            hasChildren: true
          }+"}"
       }
       else
       {
         this.nodes+="{"+name=key,
         children: [
          { name: results[key] }
        ]+"}"
       }
      }
  </code></pre>
  
  <p>Finally When i tried to display my data in console.</p>
  
  <pre><code>console.log(this.nodes);
  </code></pre>
  
  <p>Above my code does not work. Can someone help me to make this work? Any help would be appreciated. Thank you.</p>