I have a JSON array from DB, and I want it to manipulate. Currently it has discreet 8 elements, I want the array to manipulate it to get 2 elements, rest elements will be nested. My current JSON has this structure:
{
"itemId": 1,
"desc": [{
"type": "A",
"size": "xx",
"count": 12,
"price": 122
},
{
"type": "A",
"size": "xl",
"count": 18,
"price": 180
},
{
"type": "B",
"size": "xx",
"count": 12,
"price": 122
},
{
"type": "B",
"size": "xl",
"count": 12,
"price": 122
}]
}
I want the data to be manipulated to come like this:
{
"type": "A",
"desc":{
"size": "xx",
"count": 12,
"price": 122
},
{
"size": "xl",
"count": 12,
"price": 122
},
},
{
"type": "B",
"desc":{
"size": "xx",
"count": 12,
"price": 122
},
{
"size": "xl",
"count": 12,
"price": 122
},
}
I am using for each loop, but this is creating individual elements, i want just two elements in the resulting array. Any solution will be appreciated.
data-structure/schemaseems to be malformed. Please correct it. Should it be[{"type": "A", "desc": [{...}, {...}]}, {...}]?