I would like to transform belo input.json file. I would like to merge all the category key into one and create array of names, if it matches.
I am looking for a solution using only lodash or only JS/ES*
There are similar questions already asked, but most of them involve two different json's. Please shed some light on the solution
[
{
"category": "Salman Khan",
"names": "Bhaijan"
},
{
"category": "Salman Khan",
"names": "Sallu"
},
{
"category": "Salman Khan",
"names": "Dabangg Khan"
},
{
"category": "Salman Khan",
"names": "Sultan"
},
{
"category": "Shahrukh Khan",
"names": "SRK"
},
{
"category": "Shahrukh Khan",
"names": "King Khan"
},
{
"category": "Akshay Kumar",
"names": "Khiladi"
},
{
"category": "Akshay Kumar",
"names": "Akki"
},
{
"category": "Aamir Khan",
"names": "A.K."
},
{
"category": "Aamir Khan",
"names": "Mr. Perfectionist"
},
{
"category": "Priyanka Chopra",
"names": "Piggy Chops"
},
{
"category": "Kareena Kapoor",
"names": "Bebo"
}
]
expected json
[
{
"category": "Salman Khan",
"names": ["Bhaijan", "Sallu", "Dabangg Khan", "Sultan"]
},
{
"category": "Shahrukh Khan",
"names": ["SRK", "King Khan"]
},
{
"category": "Akshay Kumar",
"names": ["Khiladi", "Akki", "A.K."]
},
{
"category": "Aamir Khan",
"names": ["Mr. Perfectionist"]
},
{
"category": "Priyanka Chopra",
"names": ["Piggy Chops"]
},
{
"category": "Kareena Kapoor",
"names": ["Bebo"]
}
]