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
ist das "neuere" Objekt. Die Absicht ist daher, dass die Elemente in OBJ2 die Elemente in OBJ1 aktualisieren.
Nehmen wir an, ich habe zwei JSON -Objekte ([code]obj1[/code] und obj2 ), die demselben Schema folgen: [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] ist das "neuere" Objekt. Die Absicht ist daher, dass die Elemente in OBJ2 die Elemente in OBJ1 aktualisieren.
Ich möchte die Unterschiede zwischen zwei Zeichenfolgen in einer Farbe unter Verwendung von Python-Code hervorheben. sentence1 = I'm enjoying the summer breeze on the beach while I do some pilates....
Ich frage mich, ob es möglich ist, Total Konvertierung mit dem resultierenden Array -Einzelelement -Ändern in eine Anweisung zu verschmelzen.
Dies funktioniert perfekt
var response =...