Hello there, I need some help with grouping two JSON objects into a single array by common values.
Here is the initial input:
const json = {
"2280492":[
{
"ID":"2280492",
"Name":"Paula Luying",
"Surname":"Domingo",
"Estate":"End",
"Date_End":"4/15/2021 12:31",
"Date_final":"4/22/2021 13:57",
"Time":"7 days 1 hours",
"Note":"7.83"
},
{
"ID":"2280492",
"Name":"Paula Luying",
"Surname":"Domingo",
"Estate":"End",
"Date_End":"4/22/2021 13:58",
"Date_final":"4/23/2021 11:36",
"Time":"21 hours 38 minutes",
"Note":"0"
}
],
"2423536":[
{
"ID":"2423536",
"Name":"Josep",
"Surname":"Mora",
"Estate":"Acabat",
"Date_End":"4/19/2021 10:31",
"Date_final":"4/19/2021 11:19",
"Time":"48 minutes 33 seconds",
"Note":"9"
},
{
"ID":"2423536",
"Name":"Josep",
"Surname":"Mora",
"Estate":"Acabat",
"Date_End":"4/19/2021 11:20",
"Date_final":"4/22/2021 22:43",
"Time":"3 days 11 hours",
"Note":"4.67"
}
]
}
I want to transform this data into the following output format where common tags like "ID", "NAME,"Surname" are grouped and there is an additional tag called activities for unique data:
const json = [
{
"ID":"2280492",
"Name":"Paula Luying",
"Surname":"Domingo",
"Activities":[
{
"Estate":"End",
"Date_End":"4/15/2021 12:31",
"Date_final":"4/22/2021 13:57",
"Time":"7 days 1 hours",
"Note":"7.83"
},
{
"Estate":"End",
"Date_End":"4/22/2021 13:58",
"Date_final":"4/23/2021 11:36",
"Time":"21 hours 38 minutes",
"Note":"0"
}
]
},
{
"ID":"2423536",
"Name":"Josep",
"Surname":"Mora",
"Activities":[
{
"Estate":"Acabat",
"Date_End":"4/19/2021 10:31",
"Date_final":"4/19/2021 11:19",
"Time":"48 minutes 33 seconds",
"Note":"9"
},
{
"Date_End":"4/19/2021 11:20",
"Date_final":"4/22/2021 22:43",
"Time":"3 days 11 hours",
"Note":"4.67"
}
]
}
]