JSON Schema Compatibility Checker

0.3.1 · active · verified Thu Apr 09

jsoncompat provides Python bindings for a Rust core, enabling robust checking of compatibility between evolving JSON schemas and automatic generation of representative sample data. It helps developers ensure backward and forward compatibility for APIs and data storage, preventing unintended breaking changes. The current version is 0.3.1, and it maintains an active release cadence.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `jsoncompat` to check the compatibility between two JSON schemas and generate a sample value from a given schema. Schemas are provided as JSON strings, and the `check_compat` function requires a 'role' parameter to specify the direction of compatibility checking.

import jsoncompat as jsc
import os

# Define old and new schemas as JSON strings
old_schema = '{"type": "string"}'
new_schema = '{"type": "number"}'

# Check compatibility (role: "serializer", "deserializer", or "both")
# Raises ValueError for invalid schemas or unsupported compatibility features.
try:
    is_compatible = jsc.check_compat(old_schema, new_schema, role="both")
    print(f"Schemas compatible (both roles): {is_compatible}")

    # Example of generating a value from a schema
    schema_with_enum = '{"type": "string", "enum": ["foo", "bar"]}'
    generated_value = jsc.generate_value(schema_with_enum)
    print(f"Generated value for schema: {generated_value}")

except ValueError as e:
    print(f"An error occurred: {e}")

view raw JSON →