1
How do I group a json according to a field?
I have the following json:
{
"origem": [
{
"id": 154826,
"nm": "",
"tp": "",
"am": "",
"sg": "SAO",
"sq": 925
},
{
"id": 2289,
"nm": "",
"tp": "",
"am": "",
"sg": "RIO",
"sq": 925
},
{
"id": 154826,
"nm": "",
"tp": "",
"am": "",
"sg": "SAO",
"sq": 925
}
]
}
I wanted to group it according to the id so it looks like this:
{
"origem": [
{
"id": 154826,
"nm": "",
"tp": "",
"am": "",
"sg": "SAO",
"sq": 925
},
{
"id": 2289,
"nm": "",
"tp": "",
"am": "",
"sg": "RIO",
"sq": 925
}
]
}
In case it would be more remove the repeated items. Does anyone know how to do this?
But what about the
"sg": "SAO",
and"sg": "RIO",
? Will get lost?– Guilherme Nascimento
@Guilhermenascimento Not because all who repeat id are equal. So I only need one and eliminate the rest
– usuario
I was just wondering, because I was thinking of suggesting something different but that I would group anyway.
– Guilherme Nascimento