I am writing an API to merge two different JSON Objects. Both of these objects can have same as well different number of properties.
Object 1 :
{
"name": "Sam",
"lastName": "Hanks",
"address":[
{
"addressLine1": "123 St.",
"addressLine2": "xyz avenue",
"phone": "1231-123-123"
},
{
"addressLine1": "123 Building",
"addressLine2": "xyx state Apt.",
"phone": "1234-124-124"
}
],
"additionalInfo":{
"age": 23,
"height":"1.65",
"weight": 45
}
}
Object 2:
{
"name": "Tom",
"lastName": "Hanks",
"address":[
{
"addressLine1": "123 St.",
"addressLine2": "xyz avenue",
"phone": "1231-124-124"
}
],
"additionalInfo":{
"height":"1.65",
"weight": 89
}
}
These two objects when compared on the basis of properties, name, lastName, address, etc, will have some differences.
I would be getting all these differences in a data structure and will present it to the user as conflicts.
I have the code to get all the differences but I am not able to construct a data model to present it in a graceful way. A way which is readable and also at the same time can be parsed easily again when user resolve the conflict and I contruct a combined object in the next operation.
I have looked at many applications like, diffchecker, to see how they do it, but I am not able get some clue.
Is there a good way to do it using REST APIs ? All I want to know is, how can I represent differences in two json objects in json format.