You may use schema (PyPi Link)

schema is a library for validating Python data structures, such as those obtained from config-files, forms, external services or command-line parsing, converted from JSON/YAML (or something else) to Python data-types.

from schema import Schema, And, Use, Optional, SchemaError

def check(conf_schema, conf):
    try:
        conf_schema.validate(conf)
        return True
    except SchemaError:
        return False

conf_schema = Schema({
    'version': And(Use(int)),
    'info': {
        'conf_one': And(Use(float)),
        'conf_two': And(Use(str)),
        'conf_three': And(Use(bool)),
        Optional('optional_conf'): And(Use(str))
    }
})

conf = {
    'version': 1,
    'info': {
        'conf_one': 2.5,
        'conf_two': 'foo',
        'conf_three': False,
        'optional_conf': 'bar'
    }
}

print(check(conf_schema, conf))
Answer from Danil Speransky on Stack Overflow
🌐
PyPI
pypi.org › project › schema
schema · PyPI
Use the Python type name directly. It will be converted to the JSON name: ... Surround a schema with []. ... Use the value itself. ... You can use the name and description parameters of the Schema object init method. To add description to keys, replace a str with a Literal object. ... Note that this example is not really useful in the real world, since const already implies the type. ... The following JSON schema validations cannot be generated from this library.
      » pip install schema
    
Published   Oct 11, 2025
Version   0.7.8
🌐
jsonschema
python-jsonschema.readthedocs.io › en › latest › validate
Schema Validation - jsonschema 4.26.1.dev25+gad0a1b301 documentation
The Basics: The simplest way to validate an instance under a given schema is to use the validate function. The Validator Protocol: jsonschema defines a protocol that all validator classes adhere to...
Discussions

validation - How to validate structure (or schema) of dictionary in Python? - Stack Overflow
I have a dictionary with config info: my_conf = { 'version': 1, 'info': { 'conf_one': 2.5, 'conf_two': 'foo', 'conf_three': False, 'optional_conf': 'bar' ... More on stackoverflow.com
🌐 stackoverflow.com
I wrote okjson - A fast, simple, and pythonic JSON Schema Validator
https://github.com/mufeedvh/okjson/blob/main/okjson/validator.py It's useful to use a formatter/linter and configure your text editor to be aligned with the linter. $> pylint okjson | grep 'Bad indentation' | wc -l 100 black is a popular formatter used by the community. https://github.com/psf/black pylint is a useful listing tool. https://pylint.pycqa.org/en/latest/ Best of luck to you on your project. More on reddit.com
🌐 r/Python
4
14
March 31, 2022
Python tools/libraries to validate a JSON schema - Stack Overflow
We don’t allow questions seeking ... software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations. Closed 4 years ago. The community reviewed whether to reopen this question 4 years ago and left it closed: ... I do not want to validate an instance against a JSON schema, but I would ... More on stackoverflow.com
🌐 stackoverflow.com
Validation library for Python and JavaScript?
You are looking for JSON Schema which is a standard to define Schemas for JSON files. I don’t know for Python, but for JavaScript there are tons of options to create validated form JSON Schema More on reddit.com
🌐 r/ExperiencedDevs
6
0
November 2, 2022
🌐
jsonschema
python-jsonschema.readthedocs.io › en › stable › validate
Schema Validation - jsonschema 4.26.0 documentation
The Basics: The simplest way to validate an instance under a given schema is to use the validate function. The Validator Protocol: jsonschema defines a protocol that all validator classes adhere to...
🌐
Python-cerberus
docs.python-cerberus.org
Cerberus — Data validation for Python
>>> schema = {'name': {'type': 'string'}} >>> v = Validator(schema)
🌐
Yeah Hub
yeahhub.com › home › 7 best python libraries for validating data
7 Best Python Libraries for Validating Data - Yeah Hub
July 23, 2025 - Cerberus is a lightweight and extensible data validation library for Python. Cerberus provides type checking and other base functionality out of the box and is designed to be non-blocking and easily extensible, allowing for custom validation. It has no dependencies and is thoroughly tested under Python 2.6, Python 2.7, Python 3.3, Python 3.4, Python 3.5, Python 3.6, PyPy and PyPy3. ... >> schema = {‘name’: {‘type’: ‘string’}, ‘age’: {‘type’: ‘integer’, ‘min’: 10}} >>> document = {‘name’: ‘Little Joe’, ‘age’: 5} >>> v.validate(document, schema) False >>> v.errors {‘age’: [‘min value is 10’]}
🌐
GitHub
github.com › vajol › python-data-engineering-resources › blob › main › resources › data-schema-validation.md
python-data-engineering-resources/resources/data-schema-validation.md at main · vajol/python-data-engineering-resources
It allows for data parsing and validation using Python's standard typing module, ensuring that the data conforms to defined schemas. ... Description: Marshmallow is an ORM/ODM/framework-agnostic library for object serialization and deserialization, aimed at converting complex data types, such as objects, to and from native Python datatypes.
Author   vajol
Top answer
1 of 10
76

You may use schema (PyPi Link)

schema is a library for validating Python data structures, such as those obtained from config-files, forms, external services or command-line parsing, converted from JSON/YAML (or something else) to Python data-types.

from schema import Schema, And, Use, Optional, SchemaError

def check(conf_schema, conf):
    try:
        conf_schema.validate(conf)
        return True
    except SchemaError:
        return False

conf_schema = Schema({
    'version': And(Use(int)),
    'info': {
        'conf_one': And(Use(float)),
        'conf_two': And(Use(str)),
        'conf_three': And(Use(bool)),
        Optional('optional_conf'): And(Use(str))
    }
})

conf = {
    'version': 1,
    'info': {
        'conf_one': 2.5,
        'conf_two': 'foo',
        'conf_three': False,
        'optional_conf': 'bar'
    }
}

print(check(conf_schema, conf))
2 of 10
36

Use Pydantic!

Pydantic enforces type hints at runtime, and provides user friendly errors when data is invalid. Define how data should be in pure, canonical python; validate it with pydantic, as simple as that:

from pydantic import BaseModel


class Info(BaseModel):
    conf_one: float
    conf_two: str
    conf_three: bool

    class Config:
        extra = 'forbid'


class ConfStructure(BaseModel):
    version: int
    info: Info

If validation fails pydantic will raise an error with a breakdown of what was wrong:

my_conf_wrong = {
    'version': 1,

    'info': {
        'conf_one': 2.5,
        'conf_two': 'foo',
        'conf_three': False,
        'optional_conf': 'bar'
    }
}

my_conf_right = {
    'version': 10,

    'info': {
        'conf_one': 14.5,
        'conf_two': 'something',
        'conf_three': False
    }
}

model = ConfStructure(**my_conf_right)
print(model.dict())
# {'version': 10, 'info': {'conf_one': 14.5, 'conf_two': 'something', 'conf_three': False}}

res = ConfStructure(**my_conf_wrong)
# pydantic.error_wrappers.ValidationError: 1 validation error for ConfStructure
#     info -> optional_conf
# extra fields not permitted (type=value_error.extra)
Find elsewhere
🌐
GitHub
github.com › keleshev › schema
GitHub - keleshev/schema: Schema validation just got Pythonic · GitHub
This can be used to add word completion, validation, and documentation directly in code editors. The output schema can also be used with JSON schema compatible libraries. Just define your schema normally and call .json_schema() on it. The output is a Python dict, you need to dump it to JSON.
Starred by 2.9K users
Forked by 217 users
Languages   Python
🌐
Pydantic
docs.pydantic.dev › latest
Welcome to Pydantic - Pydantic Validation
Sign up for our newsletter, The ... & tutorials on Pydantic, Logfire, and Pydantic AI: Powered by type hints — with Pydantic, schema validation and serialization are controlled by type annotations; less to learn, less code to write, and integration with your IDE and static analysis tools. Learn more… · Speed — Pydantic's core validation logic is written in Rust. As a result, Pydantic is among the fastest data validation libraries for Python...
🌐
GitHub
github.com › python-openapi › openapi-schema-validator
GitHub - python-openapi/openapi-schema-validator: OpenAPI schema validator is a Python library that validates schema against OpenAPI Schema Specification v3.0 and v3.1
from openapi_schema_validator import validate # A sample schema schema = { "type": "object", "required": [ "name" ], "properties": { "name": { "type": "string" }, "age": { "type": ["integer", "null"], "format": "int32", "minimum": 0, }, "birth-date": { "type": "string", "format": "date", }, "address": { "type": 'array', "prefixItems": [ { "type": "number" }, { "type": "string" }, { "enum": ["Street", "Avenue", "Boulevard"] }, { "enum": ["NW", "NE", "SW", "SE"] } ], "items": False, } }, "additionalProperties": False, } # If no exception is raised by validate(), the instance is valid. validate({"name": "John", "age": 23, "address": [1600, "Pennsylvania", "Avenue"]}, schema) validate({"name": "John", "city": "London"}, schema) Traceback (most recent call last): ...
Starred by 122 users
Forked by 35 users
Languages   Python 98.3% | Makefile 1.7% | Python 98.3% | Makefile 1.7%
🌐
PyPI
pypi.org › project › jsonschema
jsonschema - JSON Schema validation for Python
>>> from jsonschema import validate >>> # A sample schema, like what we'd get from json.load() >>> schema = { ... "type" : "object", ... "properties" : { ... "price" : {"type" : "number"}, ... "name" : {"type" : "string"}, ... }, ... } >>> # ...
      » pip install jsonschema
    
Published   Jan 07, 2026
Version   4.26.0
🌐
Couchbase
couchbase.com › home › validate json documents in python using pydantic
JSON Validation Against Pydantic Schema Tutorial | Couchbase
June 14, 2025 - Find out how to validate JSON documents against a specified schema using the popular Python library pydantic. Get validation best practices at Couchbase.
🌐
TechTutorialsX
techtutorialsx.com › 2020 › 03 › 05 › python-json-schema-validation
Python: JSON schema validation – techtutorialsx
March 5, 2020 - In this tutorial we will learn how to perform JSON schema validations using Python and the jsonschema module.
🌐
Built In
builtin.com › software-engineering-perspectives › python-json-schema
How to Use JSON Schema to Validate JSON Documents in Python | Built In
An introduction to JSON Schema. | Video: Automation Step-by-Step · In Python, we can use the jsonschema library to validate a JSON instance (also referred to as a JSON document as long as it’s unambiguous) against a schema.
🌐
Python-cerberus
docs.python-cerberus.org › schemas.html
Validation Schemas - Cerberus — Data validation for Python
By default all keys in a document are optional unless the required-rule is set True for individual fields or the validator’s :attr:~cerberus.Validator.require_all is set to True in order to expect all schema-defined fields to be present in the document.
🌐
Andrewvillazon
andrewvillazon.com › validate-yaml-python-schema
Validate YAML in Python with Schema
from schema import Schema, SchemaError import yaml config_schema = Schema({ "application": { "logging": { "filename": lambda fp: fp.endswith(".log") } } }, ignore_extra_keys=True) conf_as_yaml = """ application: database: connection_string: sqlite:///app.db logging: filename: logs.log concurrency: workers: 6 """ configuration = yaml.safe_load(conf_as_yaml) try: config_schema.validate(configuration) print("Configuration is valid.") except SchemaError as se: raise se · Configuration is valid. Notice how the logging key is validated, but the surrounding keys are not. Another option for ignoring keys is to define a rule using the object type. Because every object in Python is an object type, these keys are always valid.
🌐
Reddit
reddit.com › r/python › i wrote okjson - a fast, simple, and pythonic json schema validator
r/Python on Reddit: I wrote okjson - A fast, simple, and pythonic JSON Schema Validator
March 31, 2022 -

I had a requirement to process and validate large payloads of JSON concurrently for a web service, initially I implemented it using jsonschema and fastjsonschema but I found the whole JSON Schema Specification to be confusing at times and on top of that wanted better performance. Albeit there are ways to compile/cache the schema, I wanted to move away from the schema specification so I wrote a validation library inspired by the design of tiangolo/sqlmodel (type hints) to solve this problem easier.

Here is a simple example:

from okjson import JSONValidator

schema = { 'name': str, 'age': int }

json_string = '{ "name": "Charly Gordon", "age": 32 }'

assert JSONValidator().is_valid(instance=json_string, schema=schema)

There is an example covering all the features in the README.

It also has well defined exceptions for each error case when you want to get the reason for the validation failure. (Helpful when you want to show user facing error messages)

GitHub: https://github.com/mufeedvh/okjson

This is my first time publishing a Python library, please share your feedback/suggestions. :)

🌐
GeeksforGeeks
geeksforgeeks.org › python › introduction-to-python-jsonschema
Introduction to Python jsonschema - GeeksforGeeks
July 23, 2025 - A schema defines the structure and constraints for JSON data, ensuring that the data adheres to specific rules and formats. The jsonschema library allows developers to define these rules and validate JSON data accordingly. To install the jsonschema, ...