JSON Schema
Validate JSON against a schema using jsonschema for detailed structural and type validation.
Validate JSON against a schema using jsonschema for detailed structural and type validation.
from jsonschema import validate, ValidationError
schema = {
"type": "object",
"required": ["name", "email"],
"properties": {
"name": {"type": "string", "minLength": 1},
"email": {"type": "string", "format": "email"},
"age": {"type": "integer", "minimum": 0}
}
}
try:
validate(instance={"name": "Alice", "email": "alice@example.com", "age": 30}, schema=schema)
except ValidationError as e:
print(e.message)
JSON Schema is language-agnostic — generate it from Pydantic models to reuse across languages.