Fast JSON Schema Validator for Python

2.21.2 · active · verified Sat Mar 28

A high-performance JSON schema validator for Python, currently at version 2.21.2, with a release cadence of approximately one release per year.

Warnings

Install

Imports

Quickstart

A simple example demonstrating how to define a JSON schema, compile it using 'fastjsonschema', and validate data against it.

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}')

view raw JSON →