I have a json with a main key called section and nested objects of each product within products array.
My json:
{
"data": [
{
"section": 0,
"products": [
{
"product": "Name 1",
"rate": 79.96
},
{
"product": "Name 2",
"rate": 45.96
}
]
},
{
"section": 1,
"products": [
{
"product": "Name 1",
"rate": 86.06
},
{
"product": "Name 2",
"rate": 98.96
}
]
},
{
"section": 2,
"products": [
{
"product": "Name 1",
"rate": 78.95
},
{
"product": "Name 2",
"rate": 24.96
}
]
},
{
"section": 3,
"products": [
{
"product": "Name 1",
"rate": 76.11
},
{
"product": "Name 2",
"rate": 74.96
}
]
},
{
"section": 4,
"products": [
{
"product": "Name 1",
"rate": 76.07
},
{
"product": "Name 2",
"rate": 58.96
}
]
},
{
"section": 5,
"products": [
{
"product": "Name 1",
"rate": 81.15
},
{
"product": "Name 2",
"rate": 15.96
}
]
}
]
}
How am I able to search within the products in all the sections and find the lowest rate for a product with the uniqueness of each product name within the whole data and push to its own object or array?
result example:
{
"data": [
{
"product": "Name 1",
"rate": 76.07,
"section": 4
},
{
"product": "Name 2",
"rate": 15.96,
"section": 5
}
]
}
I would of course show what I've done so far, but I'm not sure even where and how to start.
Thank you in advance!