What is a JSON diff?
A JSON diff compares two JSON documents and reports the differences between them. A plain text diff is not enough for JSON, because the same data can be written in many ways: keys in a different order, different indentation, 1.0 instead of 1. A structural JSON diff parses both sides first and compares the data, so it only reports changes that a program reading the JSON would notice. This tool shows both views: a list of changed paths such as env.LOG_LEVEL and a side-by-side view with the changed words highlighted.
How to compare two JSON files
- Paste the original on the left and the changed version on the right, or open or drop a file on each side.
- The comparison runs automatically. Compare structure (default) ignores key order and formatting; Compare text compares the files as written.
- Read the summary and the list of changed paths, then scroll the side-by-side view or use Previous / Next to jump between changes.
Example
Comparing these two service definitions (click Sample above to load them):
{"version": "2.4.1", "replicas": 3, "ports": [8080, 9090],
"env": {"LOG_LEVEL": "info", "DB_POOL_SIZE": 20, "CACHE_TTL": 300}}
{"version": "2.5.0", "replicas": 5, "ports": [8080, 9090, 9443],
"env": {"DB_POOL_SIZE": 20, "LOG_LEVEL": "debug", "REGION": "eu-west-1"}}
gives this list of changes:
| Change | Path | Value |
|---|---|---|
| changed | version | "2.4.1" β "2.5.0" |
| changed | replicas | 3 β 5 |
| added | ports[2] | 9443 |
| changed | env.LOG_LEVEL | "info" β "debug" |
| removed | env.CACHE_TTL | 300 |
| added | env.REGION | "eu-west-1" |
The swapped order of LOG_LEVEL and DB_POOL_SIZE is not reported, because JSON objects are unordered.
How the comparison works
Objects are compared key by key. Arrays are aligned with a longest-common-subsequence match, so an inserted or deleted element does not make every later element look changed; items that were modified rather than replaced are compared recursively, which yields paths such as items[3].price. For the side-by-side view both documents are printed with sorted keys and the same indentation, then compared line by line with the Myers diff algorithm (the one Git uses by default), and changed words inside each line are highlighted.
Invalid JSON on either side is reported with its line number; fix it with the JSON validator, or switch to Compare text. For YAML files use the YAML diff, and for any other text the text diff.