Configuration & Data Formats

jsonschema

The rulebook checker that makes sure a piece of JSON actually follows the rules it claims to follow.

Install it: pip install jsonschema

What does it do?

JSON Schema is a formal way of describing what a valid piece of JSON data should look like, which fields are required, what type each should be, what values are allowed, and the jsonschema library checks real JSON data against that rulebook. Picture a standardized job application form with clearly labeled required fields; this library is the clerk who rejects any submission missing a signature or with a phone number typed into the salary field. You write the rules once as a schema, then validate as much incoming data as you want against it. If something fails, it explains precisely which rule was broken and where.

See it in action

This checks a small piece of data against a rulebook that requires a name field to exist, confirming the data follows the required structure before moving on.

from jsonschema import validate

schema = {
    "type": "object",
    "properties": {"name": {"type": "string"}},
    "required": ["name"],
}

validate(instance={"name": "Ada"}, schema=schema)
print("valid!")

Why would a non-developer care?

Any time software accepts data from an outside source, another company’s system, a file a user uploaded, an API response, there’s a real risk that data is malformed or incomplete. This library is part of the invisible plumbing that catches those problems before they cause a crash or corrupt something important.

Real-world examples

JSON Schema itself is an open, widely adopted specification used across the tech industry, and jsonschema is the standard Python implementation of it, used heavily in API tooling, configuration validation, and automated testing pipelines. Tools that generate API documentation, like those built around the OpenAPI specification, frequently rely on JSON Schema under the hood to describe exactly what data an API expects.

Who uses it

Developers building or consuming APIs, and teams who need to enforce strict data contracts between different systems or companies.

How it compares to alternatives

Where Pydantic and marshmallow validate data using Python-specific class definitions, jsonschema validates against the language-agnostic JSON Schema specification, meaning the same schema could also validate data in JavaScript, Java, or any other language with a JSON Schema library.

New to Python and want to actually try libraries like this yourself?

Find a beginner-friendly course

Related libraries