The jsonschema package validates Python data against JSON Schema documents. It supports modern drafts, lazy validation reporting, and optional format checking extras installed via pip.
Overview
jsonschema is a Python library that checks whether JSON-compatible Python objects satisfy a JSON Schema. The validate function raises ValidationError with details when types or constraints fail.
Supported specification drafts include Draft 2020-12, 2019-09, Draft 7, Draft 6, Draft 4, and Draft 3. Iterative validation can list multiple failures, and programmatic helpers identify which properties or items broke rules.
Install with pip install jsonschema. Optional format and format-nongpl extras add dependencies for format validation, though formats are not checked unless you enable them per the spec. A separate check-jsonschema CLI package wraps validation for shell use.
Development uses nox for multi-version test runs, with benchmarks available through pyperf.
Key features
- validate API with detailed errors
- Multiple JSON Schema draft support
- Iterative reporting of all failures
- Optional format validation extras
- Queryable failed properties and items
- PyPI package with pip install jsonschema
Use cases
- Validate API request bodies in Python
- Check config files against schemas in CI
- Reject malformed JSON before processing