troubleshooting Question

How do I convert JSON response to structured object?

Avatar of Gustavo Baptista
Gustavo Baptista asked on
JSONAngular
16 Comments3 Solutions29 ViewsLast Modified:
Hi Experts,
this is the response I'm getting from my API:
{"0": 
   {
     "text": "Entity_1",
     "value": "",
     "collapsed": true,
     "children": {
        "text": "Location_1",
        "value": "",
        "children": {
           "text": "Service_1",
           "value": "370"
        }
     }
   }
}
{
    "1": {
        "text": "Entity_1",
        "value": "",
        "collapsed": true,
        "children": {
            "text": "Location_1",
            "value": "",
            "children": {
                "text": "Service_2",
                "value": "61"
            }
        }
    }
}
{
    "95": {
        "text": "Entity_2",
        "value": "",
        "collapsed": true,
        "children": {
            "text": "Location_2",
            "value": "",
            "children": {
                "text": "Service_45",
                "value": "PP124"
            }
        }
    }
}

Open in new window


What I want, is to group the Entities & Services so I can feed a Treeview component, like so:
{
   text: "Entity_1",
   value: "",
   collapsed: true,
   children: {
      text: "Location_1",
      value: "",
      children: [
         { text: "Service_1", value: "370"},
         { text: "Service_2", value: "61"}
      ]
}
{
   text: "Entity_2",
   collapsed: true,
   children: {
      text: "Location_1",
      value: "",
      children: [
         { text: "Service_45", value: "PP124"},
      ]
}

Open in new window


Is this something I have to do on the API side, or can I "map" it in Angular?
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 3 Answers and 16 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 16 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros