Eksempler
Matching a list by id
Du skriver inn
- Original
- {"name":"UsefulVerse","version":1,"features":[{"id":"local","enabled":true},{"id":"free","enabled":true}]}
- Ny
- {"features":[{"enabled":true,"id":"free"},{"id":"local","enabled":false},{"id":"private","enabled":true}],"name":"UsefulVerse","version":2}
- Nøkkel for liste
- id
Du får
- Lagt til
- 1
- Fjernet
- 0
- Endret
- 2
- Endringer
- changed /features/[@local]/enabled: true to false; added /features/[@private]; changed /version: 1 to 2
The two items swapped places, but matching by id sees that only local changed. The new private item is added, and the version number changed. The patch has 5 operations that use array positions.
Kjørt med verktøyets egen kode.
The same documents by position
Du skriver inn
- Nøkkel for liste
- none, compare by position
Du får
- Lagt til
- 1
- Fjernet
- 0
- Endret
- 4
Without an id the tool compares item 0 with item 0 and item 1 with item 1. Because the two items swapped places, their id fields and one enabled flag all show as changed, and private is added at the end.
Kjørt med verktøyets egen kode.
Only the key order differs
Du skriver inn
- Original
- {"b":1,"a":[1,2,3]}
- Ny
- {"a":[1,2,3],"b":1}
Du får
- Lagt til
- 0
- Fjernet
- 0
- Endret
- 0
- Patch
- []
Objects are compared by key name, so a different order is not a change. The list of changes is empty and the patch has no operations.
Kjørt med verktøyets egen kode.
A number against a string
Du skriver inn
- Original
- {"a":1}
- Ny
- {"a":"1","c":null}
Du får
- Lagt til
- 1
- Fjernet
- 0
- Endret
- 1
- Endringer
- added /c: null; changed /a: 1 to "1"
JSON treats the number 1 and the string "1" as different, so a is changed. A key that exists with the value null counts as added.
Kjørt med verktøyets egen kode.