I need to merge two JSON objects.
First object:
var objectA = {
"UUID1": {
"user": {
"ID": "1"
}
},
"UUID2": {
"user": {
"ID": "2"
}
},
"UUID3": {
"user": {
"ID": "3"
}
}
}
Second object:
var objectB = {
"UUID4": {
"user": {
"ID": "4"
}
},
"UUID5": {
"user": {
"ID": "3"
}
},
"UUID6": {
"user": {
"ID": "2"
}
}
}
Expected result:
{
"UUID1": {
"user": {
"ID": "1"
}
},
"UUID2": {
"user": {
"ID": "2"
}
},
"UUID3": {
"user": {
"ID": "3"
}
},
"UUID4": {
"user": {
"ID": "4"
}
}
}
The trick is, the UUID will differ, but the primary key is the user ID. So, I need to compare the user IDs and keep only one UUID.
Is there a clever way on how to approach this? Nested loops using Object.keys(objectX).forEach
did not work for me well :(
Thank you!