Compare two JSON documents side by side, list what changed with a JSON Pointer to each change, and get the JSON Patch that turns one into the other. It runs in your browser.
What it does
Put a document in each box, Left and Right, and they are compared as you type. Differences are read from Left to Right: what only Left has is removed, what only Right has is added, and the patch turns Left into Right.
The four views
- Documents: the two boxes, to type, paste, drop a file on, or open one into.
- Side by side: both documents, line by line. What only one side has is red on the left or green on the right with a blank on the other side, and what changed is amber with the characters that differ marked. The strip at the right edge has a tick for every difference. A right click on a line offers its text to copy, from either side.
- Changes: a list of every addition, removal and change, each with the JSON Pointer to it. Click one to copy the pointer.
- Patch: the same differences as an RFC 6902 JSON Patch, one operation to a line.
What is not a difference
The members of an object have no order, so a document with its keys sorted is the same document. Numbers are compared by value with their exact digits: 1, 1.0 and 10e-1 are one number, while two 30-digit integers that differ in the last digit are two. Arrays are ordered, but they are aligned by content first, so a value put in at the start of a long array is one addition and not a change to every element after it.
A key that an object has more than once
JSON allows an object to have the same key more than once ({"a": 1, "a": 2}), and most tools silently keep the last member. Here every member is a line, and they are compared in order: the first a of Left with the first of Right, the second with the second. A member the other side has no match for is a removal or an addition, a red or a green line with a blank across. The list of changes calls a member after the first /a#2, /a#3. A JSON Pointer has no way to name one of several members with the same key, so the patch leaves those changes out, and the Patch view says how many. Moving a difference or typing over a line keeps the members of the document it changes.
Moving a difference
Between the two sides each difference has two arrows, one over the other, at its first line: the upper one moves it into the left document (Left takes what Right has there), the lower one into the right document. A difference that is taller than the window keeps its arrows at the top of what is in view.
A click on a line picks it, and then an arrow moves only the lines that are picked, not all of the difference. Ctrl (⌘ on a Mac) adds a line, or takes it away if it is picked, Shift picks everything from the line clicked last, dragging over lines picks them, and Esc, or a click on a line that is the same on both sides, lets go of them. A value is picked whole, whatever its lines. ◀ and ▶ over the comparison (Alt+←, Alt+→) move the lines that are picked, or, when none is, the difference that ▲ and ▼ (Alt+↑, Alt+↓) went to.
The document that changed is written back into its box and the comparison runs again. The view stays where it was, nothing is picked, and ▼ goes on to the next difference, from the top of what is in view, when you want it. The document is marked (changed) until it is saved: Save over each side downloads it, as the file it was read from, or as left.json or right.json. Differences only folds what is the same.
Typing over a line
A double click on a line, on either side, puts a caret in it. Type, and press Enter or click somewhere else to put it in; Esc puts the line back. What is typed takes the place of the member or the element that was on the line, and has to be JSON where it is: a value, "name": value, nothing (the line goes), or several with commas between (they are all put in). On a line that opens an object or an array only the name can be changed. If it is not JSON, the page says what is wrong and keeps the line to be put right. A line that closes an object or an array, the first line of a document, and a line that was cut short (over 400 characters) have no caret; the Documents view has all of those.
The change is made to the document itself, not to the lines on the screen: the members of the right document stay in the order it has them (the view shows both in the order of the left one), and a number keeps the way it was written.
In your tab
The comparison is made by the same Rust engine as the desktop app, compiled to WebAssembly: nothing is uploaded. This page takes up to 10 MB a document; the desktop app compares up to 128 MB at a time. To apply the patch to a document, use Patch.
Lessons
Samples to study and to try: ▶ Try it puts them in the page.
Two versions of a document
Diff compares Left with Right: what was added, removed and changed, and where — shown side by side, listed, and as a JSON Patch that turns Left into Right.
Version 1.4 and 1.5 of a service's settings
Samples: Left, Right
Left
{
"name": "orders-api",
"version": "1.4.0",
"replicas": 2,
"env": { "LOG_LEVEL": "info", "DEBUG": true },
"ports": [8080, 9090]
}Right
{
"name": "orders-api",
"version": "1.5.0",
"replicas": 3,
"env": { "LOG_LEVEL": "warn" },
"ports": [8080, 9090, 9100],
"owner": "platform"
}What it gives: 2 added · 1 removed · 3 changed
changed /version "1.4.0" → "1.5.0"
changed /replicas 2 → 3
changed /env/LOG_LEVEL "info" → "warn"
removed /env/DEBUG true
added /ports/2 9100
added /owner "platform"
Patch (RFC 6902), Left to Right:
{"op":"replace","path":"/version","value":"1.5.0"}
{"op":"replace","path":"/replicas","value":3}
{"op":"replace","path":"/env/LOG_LEVEL","value":"warn"}
{"op":"remove","path":"/env/DEBUG"}
{"op":"add","path":"/ports/2","value":9100}
{"op":"add","path":"/owner","value":"platform"}- Each difference has the JSON Pointer of where it is:
/env/DEBUG is the DEBUG in env. - On the page, Side by side marks the lines; the arrows between the two move a difference from one side to the other.
- The patch, put in Patch JSON with Left as the document, gives Right.
Arrays and the order of keys
Arrays are compared element by element, in order, and an element put in or taken out is that — not everything after it changed. The order of an object's keys is not a difference.
A step put in the middle
Samples: Left, Right
Left
{"steps": ["build", "test", "deploy"]}Right
{"steps": ["build", "lint", "test", "deploy"]}What it gives: 1 added
added /steps/1 "lint"
Patch (RFC 6902), Left to Right:
{"op":"add","path":"/steps/1","value":"lint"}- One addition at
/steps/1: test and deploy are where they were.
The same members, in another order
Samples: Left, Right
Left
{"a": 1, "b": [1, 2], "c": {"x": true}}Right
{"c": {"x": true}, "b": [1, 2], "a": 1}What it gives: the same
The documents are the same.
- An object is its members, not their order: the two are the same.
Good to know
- A key an object has more than once is valid JSON: Diff compares its members one by one,
/name#2 being the second.