title: Create treeview from array of objects including id and original path of each element (javascript)
body: <p>I have json data that looks like this:</p>
  <pre><code>
  {
  &quot;domain&quot;: {
       &quot;id&quot;: &quot;40d74976-5db2-4a57-2a62-08d80969933d&quot;,
        &quot;name&quot;: &quot;A&quot;,
        &quot;categories&quot;: {
          &quot;items&quot;: [
            {
              &quot;id&quot;: &quot;b17e674a-b64d-4224-bf93-016bc07b6349&quot;,
              &quot;name&quot;: &quot;Category A&quot;,
              &quot;path&quot;: &quot;A/Category A&quot;
            },
            {
              &quot;id&quot;: &quot;f6490fe4-98b0-4918-a419-0177000227c2&quot;,
              &quot;name&quot;: &quot;Category AA&quot;,
              &quot;path&quot;: &quot;A/Category A/Category AA&quot;
            },
            {
              &quot;id&quot;: &quot;092163a5-b96f-4453-8a22-0307c1f1abec&quot;,
              &quot;name&quot;: &quot;Category B&quot;,
              &quot;path&quot;: &quot;A/Category B&quot;
            },
            {
              &quot;id&quot;: &quot;78ac6a08-4dc4-4f60-b0fd-0411b9631c4a&quot;,
              &quot;name&quot;: &quot;Category B-2&quot;,
              &quot;path&quot;: &quot;A/Category B/Category B-2&quot;
            }
          ]
        }
     }
  }
  </code></pre>
  <p>And i would like the result to be this:</p>
  <pre><code>{
  &quot;domain&quot;: {
        &quot;id&quot; : &quot;40d74976-5db2-4a57-2a62-08d80969933d&quot;,
        &quot;name&quot;: &quot;A&quot;,
        &quot;categories&quot;: {
          &quot;items&quot;: [
            {
              &quot;id&quot;: &quot;b17e674a-b64d-4224-bf93-016bc07b6349&quot;,
              &quot;name&quot;: &quot;Category A&quot;,
              &quot;path&quot;: &quot;A/Category A&quot;
              &quot;children&quot;: [
                   {
                    &quot;id&quot;: &quot;f6490fe4-98b0-4918-a419-0177000227c2&quot;,
                    &quot;name&quot;: &quot;Category AA&quot;,
                    &quot;path&quot;: &quot;A/Category A/Category AA&quot;
                    }
                ]
            },
            {
              &quot;id&quot;: &quot;092163a5-b96f-4453-8a22-0307c1f1abec&quot;,
              &quot;name&quot;: &quot;Category B&quot;,
              &quot;path&quot;: &quot;Domain A/Category B&quot;
              &quot;children&quot; :[
                          {
                           &quot;id&quot;: &quot;78ac6a08-4dc4-4f60-b0fd-0411b9631c4a&quot;,
                           &quot;name&quot;: &quot;Category B-2&quot;,
                           &quot;path&quot;: &quot;A/Category B/Category B-2&quot;
                          }
               ]
            }
          ]
        }
     }
  }
  </code></pre>
  <p>I need to convert the json data in this way because i  want to display this in the treeview format on my vue application but also retain the original id of each element since i want to implement the feature allow adding children to each specific element if the user needs to. To do that, it would need the original path of that element and the id of the element to which the child is being added</p>