Die beiden Dokumente werden strukturell statt als Text verglichen, indem beide Bäume gemeinsam durchlaufen und alle Unterschiede mit ihrem Pfad gemeldet werden. Das macht das Ergebnis brauchbar: Eine Datei neu zu formatieren, ihre Schlüssel umzusortieren oder die Einrückung zu ändern ergibt überhaupt keinen Unterschied, während ein Textvergleich die ganze Datei als geändert meldete.
Drei Einstellungen bestimmen, was als Unterschied zählt. Die Array-Reihenfolge zu ignorieren vergleicht Arrays als Mengen, was für eine Liste von Schlagwörtern richtig und für eine geordnete Folge falsch ist. Der lockere Typvergleich behandelt die Zeichenkette 1 und die Zahl 1 als gleich, nützlich wenn eine Seite durch ein System lief, das alles in Zeichenketten verwandelt. Unveränderte Werte anzuzeigen macht die Ausgabe vollständig, statt nur Abweichungen zu melden.
Den Vergleich lesen
-
Pfade sagen wo, nicht warum:
Jeder Unterschied wird über seine Position im Baum gemeldet — genau das, was Sie brauchen, um ihn in der Quelle zu finden. Zwei Dokumente können sich in einem Feld an fünfzig Pfaden unterscheiden, wenn dieses Feld sich wiederholt.
-
Die Array-Reihenfolge zählt, sofern Sie nichts anderes sagen:
Standardmäßig ist ein verschobenes Element ein Unterschied. Bei einer geordneten Liste ist das richtig, bei einer ungeordneten Rauschen.
-
Typänderungen werden als Änderungen gemeldet:
Ein Feld, das eine Zahl war und nun eine Zeichenkette ist, unterscheidet sich auch dann, wenn es ausgedruckt gleich aussieht — und genau solche Fehler lohnt es zu finden.
-
Es vergleicht Daten, nicht Formatierung:
Leerraum, Schlüsselreihenfolge und Einrückung sind für es unsichtbar. Nehmen Sie einen Textvergleich, wenn Sie die Formatierung prüfen wollen.
Structure is compared, not text
The [msm_tool slug="json-diff"] walks both documents as trees rather than comparing them line by line as text, which means reformatting a file, reordering its keys, or changing its indentation produces no reported differences at all — a text-based comparison would flag the entire file as changed for exactly the same edit. Every genuine difference is reported by the path where it occurs in the tree.
Array order matters, until told otherwise
By default, an element that moved position within an array counts as a difference, which is correct wherever the order itself carries meaning — a sequence of steps, a list of instructions. Turning that setting off compares arrays as sets instead, which is the right mode for a list of tags, permissions or identifiers where membership matters and order does not.
What loose type comparison actually changes
With loose comparison enabled, the string `"1"` and the number `1` are treated as equal, which is useful specifically when one side of the comparison has passed through a system that turns every value into a string on the way. Left at the default strict comparison, the same pair is reported as a genuine difference.
A type change is reported even when the printed value looks identical
A field that used to hold a number and now holds a string differs structurally even if both happen to print the same digits, and that distinction is reported rather than smoothed over — it is frequently the exact kind of fault worth catching before it reaches something downstream that expected a number and receives text instead.
Why the same field can show up at many paths
Each occurrence of a value in the tree gets its own path in the report, so a field that repeats at many points in the structure produces one reported difference per occurrence rather than a single summary. That is what makes it possible to find every instance rather than fixing one and assuming the rest followed.
What it deliberately will not do
Whitespace, key order and indentation are invisible to this comparison by design, since none of them change what the data actually says. A text-based diff tool is the right choice when formatting itself is the thing being checked, rather than the values underneath it.