I have a single array. I'm posting as JSON because that's my API output.
[
{
"compId": 26,
"addonId": "1",
"addonRate": "32"
},
{
"compId": 26,
"addonId": "2",
"addonRate": "51"
},
{
"compId": 7,
"addonId": "1",
"addonRate": "11"
},
{
"compId": 7,
"addonId": "2",
"addonRate": "12"
}
]
And I want convert that array so that I can get the following output:
[
{
"addonId": "1",
"companies": {
"compId": 26,
"addonRate": "32"
},
{
"compId": 7,
"addonRate": "11"
}
},
{
"addonId": "2",
"companies": {
"compId": 26,
"addonRate": "51"
},
{
"compId": 7,
"addonRate": "12"
}
}
]
So far I'm able to extract distinct compId and addonId. But then I want add those companies in each addons and the respective rate in the sub array.
Any help would be great! Thanks