Gratis å bruke, uten konto

JSON-differanse

Sammenlign to JSON-dokumenter etter struktur, ikke linjerekkefølge. Rekkefølgen på objektnøkler ignoreres. Gå gjennom endringer, match objektarrayer etter en nøkkel, og kopier eller last ned en JSON Patch. Dataene dine forblir i denne nettleseren.

Lim inn det tidligere JSON-dokumentet.

Lim inn det oppdaterte JSON-dokumentet.

For arrayer med objekter skriver du inn en stabil egenskap, for eksempel id. Nøklene må finnes og være unike i hver array.

Hvert JSON-dokument kan inneholde opptil 200 000 tegn. Sammenligningen stopper etter 500 oppførte endringer. Arrayer kan sammenlignes etter plassering eller etter en unik tekst-/tallverdi.

Hvordan sammenligner jeg to JSON-filer?

Lim inn den opprinnelige JSON-en til venstre og den nye til høyre, og velg deretter «Sammenlign». Nøkler i objekter kan stå i vilkårlig rekkefølge. Arrayer sammenlignes etter plassering med mindre du oppgir en nøkkel, for eksempel id, for å matche poster.

Veiledning

Slik bruker du JSON-differanse

JSON Diff compares two JSON documents by structure rather than by line. Key order inside objects is ignored. You can match array items by a key such as id, see each added, removed or changed value with its path, and copy or download a JSON Patch. It does not merge the documents.

Slik gjør du

  1. Paste the earlier JSON into the Original box and the updated JSON into the New box. Each box takes up to 200,000 characters.
  2. Choose how arrays are matched: by position, or by an object key such as id. For the key option, every item in each array needs that key and the values must be unique.
  3. Press Compare JSON. Read the counts and the list of changes, then copy the summary, copy the JSON Patch or download it as json-patch.json.

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.

Når det er nyttig

  • Review what changed between two versions of a config file or an API response.
  • Spot a field that was renamed, removed or changed type after a code change.
  • Build a JSON Patch in RFC 6902 style to hand to another tool.

Begrensninger

  • Both documents must be valid JSON, with no comments or trailing commas. Each box takes up to 200,000 characters, nesting deeper than 64 levels is refused, and so is a document with more than 20,000 values or a comparison that yields more than 500 changes.
  • Matching by key needs every item to be an object with a unique string or number in that key, otherwise it stops with an error. Arrays of plain values are always compared by position.
  • The tool only shows a patch. It does not apply it, and it does not check that the patch will work in your own system.

Tips

  • Spaces, line breaks and key order do not count as changes, so minified and pretty-printed JSON can be pasted side by side.
  • For lists of records, match by an id so that a reordered list is not shown as many changes.
  • Use Copy summary for a quick note in a ticket, and the patch download when another tool needs the operations.

Kilder

Vanlige spørsmål

How do I compare two JSON files?

Paste the original on the left and the new version on the right, then press Compare JSON. The tool lists added, removed and changed values with their paths and shows counts for each kind.

Does the order of keys matter?

Not inside objects. Keys are compared by name, in sorted order. Order does matter for arrays unless you match them by a key, because by default item 0 is compared with item 0 and so on.

How does matching by key work?

Enter a property such as id. The tool pairs items that have the same value there, so moving an item is not a change. Values must be unique strings or finite numbers in both arrays, and the string "1" differs from the number 1.

What is the JSON Patch for?

It lists add, remove and replace operations that would turn the original into the new document, in the style of RFC 6902. Array operations use positions, even when the visual list matched items by id.

Why is 1 different from "1"?

JSON has separate number and string types, so changing one into the other is a real change. In the same way, a key set to null is different from a key that is missing.

Is my JSON uploaded?

No. The comparison runs in your browser and the page says your data stays there. Avoid pasting secrets on a shared computer, because the text sits in the page until you clear or close it.

Hvordan sammenligner jeg to JSON-filer?

Lim inn den opprinnelige JSON-en til venstre og den nye til høyre, og velg deretter «Sammenlign». Nøkler i objekter kan stå i vilkårlig rekkefølge. Arrayer sammenlignes etter plassering med mindre du oppgir en nøkkel, for eksempel id, for å matche poster.

Lastes JSON-en min opp?

Nei. Parsing og sammenligning utføres i denne nettleseren. Verktøyet laster ikke opp eller lagrer JSON-dataene dine. Hvert dokument kan inneholde maksimalt 200 000 tegn.

Ignorerer JSON Diff rekkefølgen på objektnøkler?

Ja. Nøkler i JSON-objekter sammenlignes etter navn, så det regnes ikke som en endring å flytte en nøkkel. Rekkefølgen i arrayer er viktig med mindre du velger en unik objektnøkkel for sammenligning.

Kan jeg sammenligne arrayer med objekter etter ID?

Ja. Velg «Etter objektnøkkel» og oppgi en egenskap, for eksempel id. Hvert element i hver array må ha en unik tekst- eller tallverdi for denne egenskapen.

Kan jeg eksportere forskjellene?

Ja. Kopier oppsummeringen eller last ned en JSON Patch. Oppdateringen bruker arrayplasseringer og følger vanlige RFC 6902-operasjoner; gå gjennom den før du bruker den på viktige data.