obj1:
{
"id": "94774",
"name": "testName",
"colour": "red",
"date": {
"year": 2021,
"month": 10,
"day": 21
}
}
< /code>
obj2:
{
"id": "86970",
"name": "testName",
"foo": "bar",
"date": {
"year": 2022,
"month": 10,
"day": 21
}
}
< /code>
I would like to compute the difference between these objects, and have the resulting changes presented in the same schema as the original objects (comments are added for clarity here, and not required in the resulting output):
{
"id": "86970", // modified
"colour": "", // removed
"foo": "bar", // added
"date": {
"year": 2022 // modified
}
}
< /code>
How would this be done? I have tried using JsonPatchDocument from Microsoft, and that can provide me with the differences between two objects, but I can't get it in the output format I'd like.
I am using C# but would consider any other relevant solutions to this problem.
Regarding Steve's comment:
How do you decide which of the two objects is the one to keep its values for building the difference json?
obj2
- это объект «более новой», поэтому цель состоит в том, что элементы в obj2 Обновление элементов в obj1 .
Допустим, у меня есть два объекта JSON ([code]obj1[/code] и obj2 ), которые следуют той же схеме: [code]obj1: { "id": "94774", "name": "testName", "colour": "red", "date": { "year": 2021, "month": 10, "day": 21 } } < /code> obj2: { "id": "86970", "name": "testName", "foo": "bar", "date": { "year": 2022, "month": 10, "day": 21 } } < /code> I would like to compute the difference between these objects, and have the resulting changes presented in the same schema as the original objects (comments are added for clarity here, and not required in the resulting output): { "id": "86970", // modified "colour": "", // removed "foo": "bar", // added "date": { "year": 2022 // modified } } < /code> How would this be done? I have tried using JsonPatchDocument from Microsoft, and that can provide me with the differences between two objects, but I can't get it in the output format I'd like. I am using C# but would consider any other relevant solutions to this problem. Regarding Steve's comment:
How do you decide which of the two objects is the one to keep its values for building the difference json?
obj2[/code] - это объект «более новой», поэтому цель состоит в том, что элементы в obj2 Обновление элементов в obj1 .