What is the best way to restructure Json with Angularjs or Jquery..
I am getting a json with following format
[
{
"address":"balh",
"lat":123,
"long":456
},
{
"address":"balh",
"lat":321,
"long":543
},
{
"address":"balh",
"lat":432,
"long":333
},
{
"address":"balh",
"lat":123,
"long":456
},
{
"address":"balh",
"lat":321,
"long":543
},
{
"address":"balh",
"lat":432,
"long":333
}
]
The format I need is to group it with three like following..
{
"1":[
{
"address":"balh",
"lat":123,
"long":456
},
{
"address":"balh",
"lat":321,
"long":543
},
{
"address":"balh",
"lat":432,
"long":333
}
],
"2":[
{
"address":"balh",
"lat":123,
"long":456
},
{
"address":"balh",
"lat":321,
"long":543
},
{
"address":"balh",
"lat":432,
"long":333
}
]
}
{and}should be[and]because it is an array. Assuming you corrected this, you wouldn't restructure the JSON string, you'd parse it and then manipulate the resulting object to create a new object with the structure you need (which you could then serialise back to a JSON string if you needed to).