check-jsonschema
check-jsonschema is a command-line interface (CLI) tool and pre-commit hook for validating JSON/YAML files against JSON schemas. It provides a convenient way to integrate schema validation into development workflows, supporting a wide range of common configuration schemas. The current version is 0.37.1, and it releases frequently to update vendored schemas and add new features.
Warnings
- breaking Python 3.9 support has been dropped.
- breaking Verbose output levels for the CLI have changed. Previously, `-v` showed checked filenames; now, `-v` shows all errors without filenames, and `-vv` (or higher) is required to display filenames checked.
- gotcha When using check-jsonschema as a pre-commit hook with custom schemas, ensure the schema paths are correct relative to the repository root or accessible via defined `$schema` IDs. Incorrect paths or unreachable references will lead to validation errors.
- gotcha check-jsonschema defaults to validating against vendored schemas for common config types (e.g., GitHub Workflows, Dependabot). If you have a custom schema with the same filename or an unconventional path, it might be ignored or validated against the wrong schema.
Install
-
pip install check-jsonschema -
pip install pre-commit && pre-commit install
Imports
- main
from check_jsonschema.main import main
Quickstart
# 1. Create a schema file (e.g., 'my_schema.json')
# echo '{"type": "object", "properties": {"name": {"type": "string"}}, "required": ["name"]}' > my_schema.json
# 2. Create a data file to validate (e.g., 'my_data.json')
# echo '{"name": "John Doe"}' > my_data.json
# 3. Run validation via CLI
# check-jsonschema --schema my_schema.json my_data.json
# 4. Integrate with pre-commit (add to .pre-commit-config.yaml)
# - repo: https://github.com/python-jsonschema/check-jsonschema
# rev: '0.37.1'
# hooks:
# - id: check-dependabot
# - id: check-github-workflows