json-pretty-diff
Made with love by Javier Lianes García in Aranjuez ❤️
This project is stable. Bug fixes will be released as issues are reported.
Overview
Generate a clean HTML report that summarizes the top-level differences between two JSON files. The report groups keys into Added, Removed, and Changed sections to make the impact of the updates easy to scan.
Why not a plain text diff?
A line diff such as diff -u old.json new.json compares text, so a file that was only reformatted or had its keys reordered shows every line as changed. jpd reads both files as JSON first: whitespace and key order do not count, true is never mistaken for 1, and what is left is shown per key in one page that opens in any browser, offline.
Installation
From PyPI (recommended)
- Ensure Python 3.9 or newer is available on your system.
- Install the package:
pip install json-pretty-diff
- Run the CLI to compare two JSON files:
jpd original.json updated.json -o diff.html
- Open
diff.htmlin your browser to explore the report.
From source
- Clone this repository.
- Install the package in editable mode:
pip install -e .
Usage
Run the command-line tool and point it to the files you want to compare:
jpd A.json B.json -o diff.html
Options
| Flag | Description |
|---|---|
-o, --output |
Path to the output HTML file. When omitted, HTML is printed to stdout. |
--open |
Open the generated HTML report in the default browser (requires -o). |
-q, --quiet |
Suppress all output except errors. |
--no-style |
Generate HTML without CSS styles (lighter output). |
--no-timestamp |
Leave the generation time out, so the same inputs always give the same report. |
--version |
Show program version and exit. |
Exit codes
0: no differences were detected (an HTML report is still generated showing "No differences").1: differences were found and the HTML describes every change.2: an error occurred (missing file, invalid JSON, or a root element that is not a JSON object) and no HTML report is produced.
Warnings never change the exit code. If the program reading the standard output stops early (for example jpd a.json b.json | head), jpd stops writing quietly and still exits with 0 or 1.
Warnings
NaN, Infinity, numbers too large for a double and object names repeated inside the same object are not valid or not advised in JSON (RFC 8259). jpd still compares such files, prints a Warning: line on stderr for each kind (silenced by -q) and lists them at the top of the report.
Use it from Python
from json_pretty_diff import compute_top_level_diff, render_html
diff = compute_top_level_diff({"a": 1, "b": True}, {"a": 1.0, "b": 1, "c": 2})
assert diff.added == ["c"] and list(diff.changed) == ["b"]
html_page = render_html(diff, include_timestamp=False)
More in the guide; every change is in the changelog.
Example
jpd fixtures/base.json fixtures/update.json -o reports/diff.html
The file diff.html will contain one section per change category with simple styles that highlight added, removed, or modified keys.
(fixtures/ and reports/ stand for your own folders.)
Limitations
- Only the first-level keys are compared (no recursive diff).
- There are no exclusions, tolerances, or advanced configuration flags.
- Console output never uses ANSI colors.
- There is no CI/CD integration; the automated test suite in
tests/runs locally (seeCONTRIBUTING.md).
Metadata
Release files for json-pretty-diff 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| json_pretty_diff-1.2.0.tar.gz | 67.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| json_pretty_diff-1.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 102.0 kB
Release files / json_pretty_diff-1.2.0.tar.gz
| Download URL | json_pretty_diff-1.2.0.tar.gz |
|---|---|
| Size | 67.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4fa806e8154e88868332f46bb96e89196cc74fd5280ccf9f5fd6f83b6cd34f36
|
|
BLAKE2b-256 checksum How to use checksums |
8ec0a6b1cfb7f9b356c398dc05044cc510ed583b474b1a93d768248fd8bf217a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.2
|
Release files / json_pretty_diff-1.2.0-py3-none-any.whl
| Download URL | json_pretty_diff-1.2.0-py3-none-any.whl |
|---|---|
| Size | 34.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
50f08f40d7ef04f5b7f0970c918a77ff72a88c8c0e26afdbf50038ec8c9853fe
|
|
BLAKE2b-256 checksum How to use checksums |
0c53cc1ecdd81f1efc7c93e67b12cb6bde4df58b4d4e02d490f0e8de623bd2bf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.2
|