Pikkola JSON Diff, tool No. 89

Two documents, and the exact places they disagree.

Paste JSON or the YAML people actually write and read the difference as a tree of paths, not as two walls of text. Every change gets a JSON Pointer, the whole difference comes out as an RFC 6902 patch, and the page applies its own patch to prove it rebuilds the other side.

5
kinds of change
6902
patch, applied
0
uploads

The comparison bench

Read the paths, not the paragraphs

A semantic diff compares values, so a reordered object is not a change and a number written as a string is. The tree names each path once, and the patch panel is the same difference in the form a program can apply.

Left JSON

Right JSON

The patch is applied in this tab.

Three ideas that make a diff readable

A text diff tells you a line changed. A semantic diff tells you which value changed, from what, to what, and whether the shape changed too.

01

Compare values, not bytes

Object keys are matched by name, so moving a key in the file is not a change. Whitespace, indentation and trailing commas never appear. Toggle key order and the page reports an order change at that path instead of pretending the values differ.

02

Every path has one spelling

A change is named by its JSON Pointer, /features/languages/2, with ~1 for a slash and ~0 for a tilde. The same path works in a patch, in a jq expression and in most schema validators, which is why the tree shows both the friendly form and the pointer.

03

A patch you can apply

The patch panel is RFC 6902: add, remove and replace with a path each. The page applies it to the left document and compares the result with the right, so a patch that looks plausible but loses an array element is caught before you paste it into a script.

What is compared, and how far it goes

The comparison is exact and local. It does not guess that a value moved, and it does not merge two documents: it reports every path where the two disagree, in a fixed order.

Part What this page does What it will not do
Object keys Matched by name; order ignored unless the toggle is on Guess that a renamed key is the same key
Arrays Compared by index; extra items are added or removed at the end, missing ones reported in reverse index order Align items by a guessed identity, or run a longest common subsequence
Number and string Reported as a type change with both values Coerce one to the other, so 8080 and "8080" look equal
Null and missing Kept apart: a null is a value, an absent key is a removal Treat them as the same absence
YAML input Read as the block and flow subset: maps, lists, quoted and plain scalars, block scalars, comments Read anchors, aliases, tags or merge keys: those are refused with a message
JSON Patch Generated as add, remove and replace and applied in the tab to check it Send a request, store the document, or patch a remote file

Two different edits at the same path can cancel out, and this diff will say so because it compares the two ends and not the journey between them. That is a strength for review and a limit for audit.

Field guide

Paths, patches and honest limits

A diff is only useful if it names the thing that changed and says what it does not know. This page compares values by path, writes the difference as an RFC 6902 patch, and proves the patch by applying it.

Why a semantic diff beats a text diff here

A text diff on JSON reports a changed line, and in a minified file that line is the whole document. A semantic diff parses both sides and walks the two trees together, so it can say that /features/languages/2 was added and that /version changed from "1.4.0" to "1.5.0". Reindenting a file changes nothing. Reordering keys changes nothing unless you ask. That is the property that makes a diff readable in review: the size of the report tracks the size of the change, not the size of the file.

The cost is that the comparison needs both documents to parse. A file with a trailing comma, a duplicate key or a tab where YAML wants spaces has no tree to compare, so the page refuses it and points at the parse error instead of running a line comparison and calling the result a semantic one.

Pointers, and why the page shows two spellings

RFC 6901 defines the JSON Pointer: the root is the empty string, each step is a slash and a key, and a literal / inside a key is written ~1 while a literal ~ is ~0. So a key named a/b becomes /a~1b, which is exactly what a patch and a schema error message will use. The friendly form, $.a["a/b"], is easier to read and is also what the filter box accepts. Showing both is the small kindness that stops a path being copied in the wrong dialect.

Array steps are numbers in a pointer and brackets in the friendly form: /items/0 and $.items[0]. The two are the same address, and the page never mixes them inside one string.

Arrays are the hard part, and this page does not pretend otherwise

Two arrays can be compared by index or by identity, and the two answers are different. By index, inserting an item at the front reports a change at every later position, which is technically true and practically noisy. By identity, the tool has to guess which key identifies an item, and a wrong guess silently rewrites the report. This page compares by index because that answer can always be given correctly and never has to be explained away. When a list of records needs an identity comparison, project it first: filter to $.items[*].id on both sides and the diff answers the question you actually had.

What the YAML reader covers

The subset is the one configuration files use: block mappings and sequences, flow collections in brackets and braces, single and double quoted scalars, plain scalars with YAML 1.2 core resolution (null, true, false, numbers), block scalars with | and >, and comments. Numbers that do not round-trip through JavaScript's Number, such as a 20-digit identifier, come out as strings, which is the safer reading.

Anchors, aliases, tags and merge keys are refused with a message naming the line, because a reader that half-supports them produces a comparison that is wrong in a way nobody notices. If a document needs them, run it through a real YAML parser to JSON first; the comparison is then exact.

The patch proves itself

The patch is generated in the same walk as the tree, so the two cannot disagree, and it is applied to the left document in the tab. The result is compared with the right document by value. If the patch applied but the result differs, the page says so; that case is rare, and it is the one worth having a test for, because it is where a hand-written patch usually fails.

Order matters inside a patch: a removal shifts the indices after it, which is why removals are emitted from the highest index down and additions after the surviving elements. A patch is written against one document and one version of it; replaying it against a document that has moved on is not a supported use, and no tool can make it one.

When the syntax rather than the meaning is the problem, Pikkola JSON formats it. When a filter answers the question better than a diff, Pikkola jq runs it.

Questions

Is my configuration sent anywhere?

No. Both documents are parsed and compared in the tab. Nothing is stored, so a reload forgets them, and the only request after the page loads is the cookieless page-view count. A file with a password in it stays where it is.

Why is a reordered object not a change?

Because JSON objects are unordered by definition: {"a":1,"b":2} and {"b":2,"a":1} are the same object, and most parsers and serialisers reorder keys anyway. If the order on disk is the thing you care about, turn on key order and the page reports it as its own kind of change instead of mixing it with value changes.

Which YAML does it read?

The subset written by hand and by most configuration tools: block mappings and sequences, flow collections, quoted and plain scalars, block scalars with | and >, comments, null, true and false. Anchors, aliases, tags and merge keys are refused rather than read wrongly. If a document needs them, convert it to JSON first and the comparison is exact.

Is the array comparison safe to rely on?

It is honest, which is not the same as clever. Arrays are compared by index, so inserting an item at the front shifts everything after it and the diff reports a change at every later index. For a list of records where order is not identity, project it to the field you care about with the filter first, and compare that.

Can I use the patch directly?

Yes, that is what it is for. The operations are plain RFC 6902 JSON, the kind git apply, jsonpatch libraries and most API tools read. The page proves the patch rebuilds the right document before showing it to you, which is the check most hand-written patches skip. One caveat: a remove on an array index is only valid against the document it was generated from.