I want to generate an object from two given objects A and B with only the values from B that differ from A. We can assume that the all fields exist in both A and B.
Example: Given the following two objects:
A
{
"firstName": "John",
"lastName": "Doe",
"nickname": "Johnny",
"location": {
"latitude": 1.0,
"longitude": 1.0
},
"email": "john.doe@company.com"
}
B
{
"firstName": "John",
"lastName": "Doe",
"nickname": "John-Boy",
"location": {
"latitude": 1.0,
"longitude": 2.0
},
"email": "john.doe@company.com"
}
As nickname and location have changed, I want the result to be:
{
"nickname": "John-Boy",
"location": {
"latitude": 1.0,
"longitude": 2.0
}
}
Note that I want the full location
object and not just the changed longitude
What would be a good way of achieving this?