1
The input data would be a list of Products as below
[ {
"id": "123",
"ean": "7898100848355",
"title": "Cruzador espacial Nikana - 3000m - sem garantia",
"brand": "nikana",
"price": 820900.90,
"stock": 1
},
{
"id": "u7042",
"ean": "7898054800492",
"title": "Espada de fótons Nikana Azul",
"brand": "nikana",
"price": 2199.90,
"stock": 82
},
{
"id": "bb2r3s0",
"ean": "2059251400402",
"title": "Corredor POD 3000hp Nikana",
"brand": "nikana",
"price": 17832.90,
"stock": 8
},
{
"id": "321",
"ean": "7898100848355",
"title": "Cruzador espacial Nikana - 3000m - sem garantia",
"brand": "trek",
"price": 790300.90,
"stock": 0
},
{
"id": "80092",
"ean": "",
"title": "Espada de Fótons REDAV Azul",
"brand": "redav",
"price": 1799.90,
"stock": 0
},
{
"id": "7728uu",
"ean": "7898100848355",
"title": "Cruzador espacial Ekul - 3000m - sem garantia",
"brand": "ekul",
"price": 1300000.00,
"stock": 1
}
]
My question is how to group the list so that it returns the output in this way:
{
"data": [
{
"description": "Espada de Fótons REDAV Azul",
"items": [
{
"id": "u7042",
"ean": "7898054800492",
"title": "Espada de fótons Nikana Azul",
"brand": "nikana",
"price": 2199.90,
"stock": 82
},
{
"id": "80092",
"ean": "",
"title": "Espada de Fótons REDAV Azul",
"brand": "redav",
"price": 1799.90,
"stock": 0
}
]
},
{
"description": "nikana",
"items": [
{
"id": "u7042",
"ean": "7898054800492",
"title": "Espada de fótons Nikana Azul",
"brand": "nikana",
"price": 2199.90,
"stock": 82
},
{
"id": "bb2r3s0",
"ean": "2059251400402",
"title": "Corredor POD 3000hp Nikana",
"brand": "nikana",
"price": 17832.90,
"stock": 8
},
{
"id": "123",
"ean": "7898100848355",
"title": "Cruzador espacial Nikana - 3000m - sem
garantia",
"brand": "nikana",
"price": 820900.90,
"stock": 1
}
]
}
]
}
What have you ever tried to do?
– user28595
I’m sorry, but be more specific in your question. But from what I understand, you could create a product object and then group by name, for example. From what I know, you’d have to write an algorithm in order to group your data. But try to study a little about object orientation that will help a lot.
– Tiago Funk