Diff Viewer
Compare two texts or two JSON documents by character, word, line, or structure.
- Recent results are kept in this browser's local storage until you clear them.
History kept on this device
Recent results are kept in this browser's local storage until you clear them. - Processing happens in this page. No application server receives your input.
Runs in your browser
Processing happens in this page. No application server receives your input.
Left
Right
Comparison
What this tool does
Compare shows what changed between two texts, by character, word or line, or between two JSON documents by value. Additions read in green with a + or an ins, removals in red with a - or a del, and the rest stays neutral. For example, {"b":2,"a":1} against {"a":1,"b":3} in JSON mode gives five rows: {, "a": 1,, - "b": 2, + "b": 3 and }, and the count 1 line removed, 1 line added.
What it does not do
It does not run as you type, show the comparison side-by-side, fold unchanged regions into collapsed ones, export a patch, do a three-way merge, or offer an option to ignore whitespace or case. Nothing you paste is sent anywhere.
The modes
- Characters compares code point by code point. Its worst case is quadratic: two long texts with little in common cost time and memory in proportion to the product of their lengths. Any comparison above a few hundred bytes therefore runs in the background, where Cancel can stop it.
- Words compares words and punctuation, and Words does not compare spacing:
a banda bread as the same. Use Lines or Characters when spacing matters. - Lines compares whole lines, and is the right choice for code and for ordered files.
- JSON compares the values of two documents, as the next section says.
JSON mode
- Both documents are parsed and their keys are sorted, so key order never shows. That is surprising when you came to see an ordered configuration file change. Use Lines when order matters.
- Array order counts:
[1,2]and[2,1]differ. -0and0,1.0and1, and two spellings of one string compare equal, because the values are equal.- A number a double cannot reproduce, such as 9007199254740993, can be rounded, so two different numbers can read as the same. A warning says so. A repeated key keeps its last value, and a warning names the side, the path and the position.
- Invalid JSON reads
Invalid JSON input for diff. The message cannot say which side was wrong, a known rough edge of this tool. - An empty side is compared in a text mode, where everything on the other side reads as added or removed, and is invalid in JSON mode, because an empty text is not a document.
How text reads
- Text is compared by code point, with no Unicode normalization, so a precomposed letter and the same letter with a combining mark differ.
- A control, a format character, a line separator or a lone surrogate shows as its escape,
\u{XXXX}, in uppercase. A line that continues on the next row begins withโช, and a last line with no line feed ends with\ No newline at end. - Changed text also escapes other spaces and default-ignorable characters, because a changed one reads as a plain space or as nothing.
- Unchanged text leaves a carriage return before its line feed, the two joiners and those characters as they are, because emoji and several scripts need them. A bidirectional character is escaped either way.
- A line breaks by an estimate of each character's width, so a row can end early, and a very wide glyph such as U+FDFD can still be cut at the row's edge. Copy holds it whole.
- Copy holds the raw text, with no escape and no continuation mark: one line per line with a sign in Lines and JSON, and
[-text-]for a removal and{+text+}for an addition in Characters and Words. Save writes the same text to a file.
Limits
Up to 1 MiB a side. Character mode is quadratic in the worst case, so all but the smallest comparisons run in the background, can be cancelled, and stop after 30 seconds. JSON mode sorts keys, so key order never shows, and Words does not compare spacing. Text is compared by code point, with no normalization.
| Bound | Value | At the bound |
|---|---|---|
| Size of each side | 1 MiB | The side that is larger than this is named and nothing runs. Both sides are named together. |
| Nesting, JSON | 64 levels | The side nested deeper is named, with the position where one can be found, before any parse. |
| Keys, JSON | 200,000 keys | The side with more keys is named, before any parse. |
| Canonical text, JSON | 16 MiB for both | Neither canonical form is built, and Lines is the way to compare them. |
| Warnings | 1,000 warnings | The rest are counted, as a last line. |
Thresholds, time and Cancel
A comparison runs on the page itself below a threshold, measured in UTF-8 bytes of the larger side, and in a background worker at and above it. The thresholds are 512 bytes for Characters, 512 bytes for Words, 512 bytes for Lines and 512 bytes for JSON. A background run that lasts a moment shows Running in the background. and Cancel, which stops it, and every such run stops by itself after 30 seconds. Below a threshold a run cannot be stopped, because it is short enough that it need not be.
Storage
Both sides and the mode are kept in this browser, and the last comparisons in the history. Over 131,072 characters in all, the sides compare and are not kept. When storage is unavailable, full or refused, that never stops a comparison: the comparison finishes, and the browser's own refusal text appears.
Scope: this covers the page itself. Your browser, operating system, clipboard, downloads, extensions, and crash recovery may keep copies, and a compromised site origin would not be protected.