Fast JSON Schema Validator for Python
raw JSON → 2.21.2 verified Tue May 12 auth: no python install: verified quickstart: verified
A high-performance JSON schema validator for Python, currently at version 2.21.2, with a release cadence of approximately one release per year.
pip install fastjsonschema Common errors
error ModuleNotFoundError: No module named 'fastjsonschema' ↓
cause The `fastjsonschema` package has not been installed in the Python environment.
fix
Install the package using pip:
pip install fastjsonschema error ImportError: cannot import name 'compile' from 'fastjsonschema.schema' ↓
cause In `fastjsonschema` version 2.21.2, the `compile` function was moved from the `fastjsonschema.schema` module directly into the `fastjsonschema` package.
fix
Update the import statement to directly import
compile from fastjsonschema: from fastjsonschema import compile error TypeError: string indices must be integers ↓
cause This error occurs when a JSON schema is passed as a string to `fastjsonschema.compile()` instead of a parsed Python dictionary.
fix
Ensure the JSON schema is parsed into a Python dictionary using
json.loads() before passing it to fastjsonschema.compile(): import json; schema_dict = json.loads(schema_string); validate = fastjsonschema.compile(schema_dict) error ModuleNotFoundError: No module named 'jsonschema' ↓
cause While `fastjsonschema` is a high-performance validator, it relies on the `jsonschema` package for certain functionalities, and this error indicates `jsonschema` is not installed.
fix
Install the
jsonschema package: pip install jsonschema error fastjsonschema.exceptions.JsonSchemaValueException: data.property must be [type] (e.g., 'data.name must be string') ↓
cause This exception is raised when the input data fails validation against the compiled JSON schema.
fix
Inspect the error message (
e.message), e.path, and e.value properties of the JsonSchemaValueException to understand which part of the data violates the schema, then modify the data to conform to the schema or adjust the schema definition. Warnings
breaking In version 2.21.2, the 'compile' function was moved from 'fastjsonschema.schema' to 'fastjsonschema'. ↓
fix Update import statements to 'from fastjsonschema import compile'.
gotcha Ensure that the 'jsonschema' package is installed, as 'fastjsonschema' depends on it for schema validation. ↓
fix Install 'jsonschema' using 'pip install jsonschema'.
gotcha The environment reports pip warnings related to running as root or requiring an update. These are not issues with the library's functionality but rather environmental concerns with pip itself. ↓
fix It is recommended to use a virtual environment or avoid running pip as the 'root' user to prevent permission issues. Consider updating pip to the latest version as suggested by the notice.
Install compatibility verified last tested: 2026-05-12
python os / libc status wheel install import disk
3.10 alpine (musl) - - 0.02s 18.0M
3.10 slim (glibc) - - 0.01s 18M
3.11 alpine (musl) - - 0.03s 19.8M
3.11 slim (glibc) - - 0.03s 20M
3.12 alpine (musl) - - 0.03s 11.7M
3.12 slim (glibc) - - 0.03s 12M
3.13 alpine (musl) - - 0.03s 11.3M
3.13 slim (glibc) - - 0.03s 12M
3.9 alpine (musl) - - 0.02s 17.5M
3.9 slim (glibc) - - 0.02s 18M
Imports
- compile
from fastjsonschema import compile
Quickstart verified last tested: 2026-04-23
import os
import fastjsonschema
# Define your JSON schema
schema = {
'type': 'object',
'properties': {
'name': {'type': 'string'},
'age': {'type': 'integer'}
},
'required': ['name', 'age']
}
# Compile the schema
validate = fastjsonschema.compile(schema)
# Validate data
data = {'name': 'John Doe', 'age': 30}
try:
validate(data)
print('Data is valid')
except fastjsonschema.exceptions.JsonSchemaException as e:
print(f'Validation error: {e.message}')