How to change/add field in JSON structure in angularjs/javascript

i am using angularjs http get method to get the data,the JSON format which i am getting is :

{"SITE1":[
    {
        "name":"name1",
        "status":"0",
        "id":23,
        "isDeleted":false
    },
    {
        "name":"name2",
        "status":"0",
        "id":13,
        "isDeleted":false
    }],

"SITE2":[
    {
        "name":"name3",
        "status":"0",
        "id":2,
        "isDeleted":false
    }
    ]}

but i want data to be in format

{"location" : "SITE1",
 "services" : [
      {
        "name":"name1",
        "status":"0",
        "id":23,
        "isDeleted":false
      },
      {
        "name":"name2",
        "status":"0",
        "id":13,
        "isDeleted":false
      }],
   "location" : "SITE2",
    "services":[
       {
        "name":"name3",
        "status":"0",
        "id":2,
        "isDeleted":false
       }
    ]}

Please help in this, how to do this.
I tried using

object["location"] = key;
 object["status"] = value;

to add these fields. but something is going wrong in this.


Source: json

Leave a Reply