Here is a JSON object that I need to restructure:
[
{
'con': 'Usa',
'city': 'ny',
'town':'as'
},
{
'con': 'Ger',
'city': 'ber',
'town':'zd'
},
{
'con': 'Usa',
'city': 'la',
'town':'ss'
}
]
I want to organize this JSON into a new structure where no two objects have the same 'con' value. The desired structure should look like this:
[{
"con": "usa",
"area": [{
"city": "ny",
"town": "as"
}, {
"city": "la",
"town": "ss"
}]
},
{
"con": "ger",
"area": [{
"city": "ber",
"town": "zd"
}]
}
]
Do you have any suggestions on how to achieve this transformation? Thank you!