A library for comparing JSON schemas and displaying differences
Project description
๐ JSON Schema Diff
A powerful, intelligent library for comparing JSON schemas with beautiful formatted output, smart parameter combination, and contextual information.
โญ Star us on GitHub | ๐ Read the Docs | ๐ Report Bug
โจ Features
- ๐ฏ Intelligent Comparison - Detects and categorizes all types of schema changes
- ๐จ Beautiful Output - Colored, formatted differences with clear symbols
- ๐ Smart Combination - Combines related parameters (e.g.,
minimum+maximum=range) - ๐ Context Aware - Shows related fields for better understanding (e.g.,
type+format) - ๐ Semantic Array Diff - Ignores pure reorder noise and reports only real adds/removes/changes
- โก High Performance - Efficient algorithms for large schemas
- ๐ ๏ธ CLI & Python API & Sphinx Extension - Use programmatically or from command line or in
.rst - ๐ง Highly Configurable - Customize behavior for your needs
๐ Quick Start
Installation
# Standard installation
pip install jsonschema-diff
30-Second Example
from jsonschema_diff import JsonSchemaDiff, ConfigMaker
from jsonschema_diff.color import HighlighterPipeline
from jsonschema_diff.color.stages import (
MonoLinesHighlighter, ReplaceGenericHighlighter, PathHighlighter
)
prop = JsonSchemaDiff(
config=ConfigMaker.make(),
colorize_pipeline=HighlighterPipeline([
MonoLinesHighlighter(),
ReplaceGenericHighlighter(),
PathHighlighter(),
])
)
prop.compare(
old_schema="context.old.schema.json",
new_schema="context.new.schema.json"
)
prop.print(with_legend=True)
Output:
Why It Beats Line-Based Diffs For Schemas
For array-like schema parts, this library performs a semantic diff:
- Pure reorder does not create noisy changes
dictelements are matched by structure (not by position)- Scalar elements are matched by value multiplicity (multiset logic)
Example:
[1, 2, 3] -> [3, 1, 2, 1]
A line-based diff typically reports multiple moved lines.
jsonschema-diff reports just one meaningful change: + 1.
CLI Usage
# Compare schema files
jsonschema-diff schema_v1.json schema_v2.json
# No colors (for logs/CI) and with exit-code
jsonschema-diff --no-color --exit-code schema_v1.json schema_v2.json
# Compare JSON strings
jsonschema-diff "{\"type\":\"string\"}" "{\"type\":\"number\"}"
Sphinx Extension
Use the extension in your build:
extensions += ["jsonschema_diff.sphinx"]
You must also configure the extension. Add the following variable to your conf.py:
from jsonschema_diff import ConfigMaker, JsonSchemaDiff
from jsonschema_diff.color import HighlighterPipeline
from jsonschema_diff.color.stages import (
MonoLinesHighlighter, PathHighlighter, ReplaceGenericHighlighter,
)
jsonschema_diff = JsonSchemaDiff(
config=ConfigMaker.make(),
colorize_pipeline=HighlighterPipeline(
[MonoLinesHighlighter(), ReplaceGenericHighlighter(), PathHighlighter()],
),
)
After that, you can use it in your .rst files:
.. jsonschemadiff:: path/to/file.old.schema.json path/to/file.new.schema.json # from folder `source`
:name: filename.svg # optional
:title: Title in virtual terminal # optional
:no-legend: # optional
๐ Output Format
| Symbol | Meaning | Color | Example |
|---|---|---|---|
+ |
Added | ๐ข Green | + ["new_field"].field: "string" |
- |
Removed | ๐ด Red | - ["old_field"].field: "string" |
r |
Changed | ๐ต Cyan | r ["field"].field: "old" -> "new" |
m |
Modified | ๐ต Cyan | m ["field"]: ... |
|
Context | โช None | ["related"]: "unchanged" |
๐๏ธ Architecture
Modern 6-stage pipeline for clean, testable code:
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ
โ DiffFinder โโโโโถโ CompareFinder โโโโโถโ CombineProcessor โ
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ
โผ
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโ
โ Formatter โโโโโโRenderProcessorโโโโโโโโ DiffProcessor โ
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโ
- DiffFinder: Finds raw differences
- CompareProcessor: Find class-processors
- Combiner: Combines related parameters
- RenderProcessor: Adds context information and render
- Formatter: Beautiful colored output
๐ ๏ธ Development
Setup
git clone https://github.com/Miskler/jsonschema-diff.git
cd jsonschema-diff
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
make build
make install-dev
Commands
# Checks
make test # Run tests with coverage
make lint # Lint code
make type-check # Type checking
# Action
make format # Format code
make docs # Build documentation
๐ Documentation
๐ค Contributing
We welcome contributions!
Quick Contribution Setup
# Fork the repo, then:
git clone https://github.com/your-username/jsonschema-diff.git
cd jsonschema-diff
# Install
make build
make install-dev
# Ensure everything works
make test
make lint
make type-check
๐ License
MIT License - see LICENSE file for details.
Made with โค๏ธ for developers working with evolving JSON schemas
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jsonschema_diff-0.1.11.tar.gz.
File metadata
- Download URL: jsonschema_diff-0.1.11.tar.gz
- Upload date:
- Size: 44.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c3b12f9955ef405d1a7be2909b9ac0b3cdde5f9b7aff20d712bf186b8a36ddad
|
|
| MD5 |
530bc78d62d892cddbce58f59f8f1dfc
|
|
| BLAKE2b-256 |
e164692c8cdab5bfb59d7a7236bd4f814e6e3397bead2e9cb2f01b5036bbf0c6
|
Provenance
The following attestation bundles were made for jsonschema_diff-0.1.11.tar.gz:
Publisher:
release.yml on Miskler/jsonschema-diff
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jsonschema_diff-0.1.11.tar.gz -
Subject digest:
c3b12f9955ef405d1a7be2909b9ac0b3cdde5f9b7aff20d712bf186b8a36ddad - Sigstore transparency entry: 1124073946
- Sigstore integration time:
-
Permalink:
Miskler/jsonschema-diff@ba52e6223e9a1a49aeae50610254aa682a80fe1b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Miskler
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ba52e6223e9a1a49aeae50610254aa682a80fe1b -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file jsonschema_diff-0.1.11-py3-none-any.whl.
File metadata
- Download URL: jsonschema_diff-0.1.11-py3-none-any.whl
- Upload date:
- Size: 50.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a85e4ad11fea5ab9cfa24938d992dbdee9f861aebb2cef3aa6c02d486c408b8
|
|
| MD5 |
22219633a30721f856143a56d332203d
|
|
| BLAKE2b-256 |
2697ceab5c2a44ad4238b6143310728b2c063db71f364919f828f6ffdefb05a4
|
Provenance
The following attestation bundles were made for jsonschema_diff-0.1.11-py3-none-any.whl:
Publisher:
release.yml on Miskler/jsonschema-diff
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jsonschema_diff-0.1.11-py3-none-any.whl -
Subject digest:
8a85e4ad11fea5ab9cfa24938d992dbdee9f861aebb2cef3aa6c02d486c408b8 - Sigstore transparency entry: 1124073987
- Sigstore integration time:
-
Permalink:
Miskler/jsonschema-diff@ba52e6223e9a1a49aeae50610254aa682a80fe1b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Miskler
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ba52e6223e9a1a49aeae50610254aa682a80fe1b -
Trigger Event:
workflow_dispatch
-
Statement type: