Python bindings for checking compatibility of evolving JSON Schemas and generating example values.
Install from PyPI:
pip install jsoncompat==0.3.1import jsoncompat as jsc
old_schema = '{"type": "string"}'
new_schema = '{"type": "number"}'
is_compatible = jsc.check_compat(old_schema, new_schema, jsc.Role.BOTH)
print(is_compatible)
# Generate example values for a schema
generator = jsc.generator_for(old_schema)
example = generator.generate_value(depth=5)
print(example)check_compat(old_schema_json: str, new_schema_json: str, role: str = "both") -> boolrolemust be"serializer","deserializer", or"both".- Raises
ValueErrorfor invalid schemas or hard unsupported compatibility features such as non-integralnumber.multipleOf.
generator_for(schema_json: str) -> Generator- Parses the schema once and returns a reusable generator.
Generator.generate_value(depth: int = 5) -> strreturns a JSON string for one generated value accepted by the schema.- Raises
ValueErrorwhen the schema is invalid, known to be unsatisfiable, or generation exhausts its retry budget.
validator_for(schema_json: str) -> Validator- Parses the schema once and returns a reusable validator.
Validator.is_valid_json(instance_json: str) -> boolvalidates JSON strings against the parsed schema.Validator.is_valid_value(instance: JsonValue) -> boolvalidates Python JSON-compatible values:None,bool, finiteint/float,str,list,tuple, anddict[str, ...].
generate_value(schema_json: str, depth: int = 5) -> str- Deprecated. Use
generator_for(schema_json).generate_value(depth)instead.
- Deprecated. Use
is_valid(schema_json: str, instance_json: str) -> bool- Deprecated. Use
validator_for(schema_json).is_valid_json(instance_json)instead.
- Deprecated. Use
jsoncompat.codegen.dataclassesruntime helpers for generated dataclass modelsRole.SERIALIZER,Role.DESERIALIZER, andRole.BOTHare string constants accepted bycheck_compat.
Schemas are passed as JSON strings. check_compat returns a boolean verdict and raises ValueError for invalid JSON, invalid schemas, or hard unsupported compatibility cases.
Run the generated dataclass runtime microbenchmark from the repository root:
env -u VIRTUAL_ENV uv run --project pybindings python pybindings/bench_dataclasses_runtime.pyMIT License. See: