Skip to main content

A library for comparing JSON schemas and displaying differences

Project description

๐Ÿ” JSON Schema Diff

logo.webp

A powerful, intelligent library for comparing JSON schemas with beautiful formatted output, smart parameter combination, and contextual information.

Tests Coverage Python PyPI - Package Version License BlackCode mypy Discord Telegram

โญ 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: ./assets/example_working.svg

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
  • dict elements 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 โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  1. DiffFinder: Finds raw differences
  2. CompareProcessor: Find class-processors
  3. Combiner: Combines related parameters
  4. RenderProcessor: Adds context information and render
  5. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jsonschema_diff-0.1.11.tar.gz (44.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jsonschema_diff-0.1.11-py3-none-any.whl (50.5 kB view details)

Uploaded Python 3

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

Hashes for jsonschema_diff-0.1.11.tar.gz
Algorithm Hash digest
SHA256 c3b12f9955ef405d1a7be2909b9ac0b3cdde5f9b7aff20d712bf186b8a36ddad
MD5 530bc78d62d892cddbce58f59f8f1dfc
BLAKE2b-256 e164692c8cdab5bfb59d7a7236bd4f814e6e3397bead2e9cb2f01b5036bbf0c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for jsonschema_diff-0.1.11.tar.gz:

Publisher: release.yml on Miskler/jsonschema-diff

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file jsonschema_diff-0.1.11-py3-none-any.whl.

File metadata

File hashes

Hashes for jsonschema_diff-0.1.11-py3-none-any.whl
Algorithm Hash digest
SHA256 8a85e4ad11fea5ab9cfa24938d992dbdee9f861aebb2cef3aa6c02d486c408b8
MD5 22219633a30721f856143a56d332203d
BLAKE2b-256 2697ceab5c2a44ad4238b6143310728b2c063db71f364919f828f6ffdefb05a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for jsonschema_diff-0.1.11-py3-none-any.whl:

Publisher: release.yml on Miskler/jsonschema-diff

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page