Skip to content

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

License

Notifications You must be signed in to change notification settings

Miskler/jsonschema-diff

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” 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)
  • ⚑ 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

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

About

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

Topics

Resources

License

Stars

Watchers

Forks