So far the closest thing I've been able to find is warlock, which advertises this workflow:

Build your schema

>>> schema = {
    'name': 'Country',
    'properties': {
        'name': {'type': 'string'},
        'abbreviation': {'type': 'string'},
    },
    'additionalProperties': False,
}

Create a model

>>> import warlock
>>> Country = warlock.model_factory(schema)

Create an object using your model

>>> sweden = Country(name='Sweden', abbreviation='SE')

However, it's not quite that easy. The objects that Warlock produces lack much in the way of introspectible goodies. And if it supports nested dicts at initialization, I was unable to figure out how to make them work.

To give a little background, the problem that I was working on was how to take Chrome's JSONSchema API and produce a tree of request generators and response handlers. Warlock doesn't seem too far off the mark, the only downside is that meta-classes in Python can't really be turned into 'code'.

Other useful modules to look for:

  • jsonschema - (which Warlock is built on top of)
  • valideer - similar to jsonschema but with a worse name.
  • bunch - An interesting structure builder thats half-way between a dotdict and construct

If you end up finding a good one-stop solution for this please follow up your question - I'd love to find one. I poured through github, pypi, googlecode, sourceforge, etc.. And just couldn't find anything really sexy.

For lack of any pre-made solutions, I'll probably cobble together something with Warlock myself. So if I beat you to it, I'll update my answer. :p

Answer from synthesizerpatel on Stack Overflow
🌐
GitHub
github.com › cwacek › python-jsonschema-objects
GitHub - cwacek/python-jsonschema-objects: Automatic Python binding generation from JSON Schemas · GitHub
python-jsonschema-objects provides an automatic class-based binding to JSON Schemas for use in python.
Starred by 373 users
Forked by 90 users
Languages   Python
🌐
Readthedocs
python-jsonschema-objects.readthedocs.io › en › latest › Introduction.html
What — Python JSONSchema Objects 0.0.18 documentation
python-jsonschema-objects provides an automatic class-based binding to JSON Schemas for use in python.
🌐
JSON Schema
json-schema.org › understanding-json-schema › reference › object
JSON Schema - object
Objects are the mapping type in JSON. They map "keys" to "values". In JSON, the "keys" must always be strings. Each of these pairs is conventionally referred to as a "property". ... In Python, "objects" are analogous to the dict type.
🌐
GeeksforGeeks
geeksforgeeks.org › python › introduction-to-python-jsonschema
Introduction to Python jsonschema - GeeksforGeeks
July 23, 2025 - A JSON Schema is itself a JSON object, which means it can be easily parsed, modified, and managed using standard JSON tools. It is widely used in APIs, configuration files, and data interchange formats to ensure that the data adheres to a defined standard. The jsonschema is a Python library used for validating JSON data against a schema...
Top answer
1 of 5
39

So far the closest thing I've been able to find is warlock, which advertises this workflow:

Build your schema

>>> schema = {
    'name': 'Country',
    'properties': {
        'name': {'type': 'string'},
        'abbreviation': {'type': 'string'},
    },
    'additionalProperties': False,
}

Create a model

>>> import warlock
>>> Country = warlock.model_factory(schema)

Create an object using your model

>>> sweden = Country(name='Sweden', abbreviation='SE')

However, it's not quite that easy. The objects that Warlock produces lack much in the way of introspectible goodies. And if it supports nested dicts at initialization, I was unable to figure out how to make them work.

To give a little background, the problem that I was working on was how to take Chrome's JSONSchema API and produce a tree of request generators and response handlers. Warlock doesn't seem too far off the mark, the only downside is that meta-classes in Python can't really be turned into 'code'.

Other useful modules to look for:

  • jsonschema - (which Warlock is built on top of)
  • valideer - similar to jsonschema but with a worse name.
  • bunch - An interesting structure builder thats half-way between a dotdict and construct

If you end up finding a good one-stop solution for this please follow up your question - I'd love to find one. I poured through github, pypi, googlecode, sourceforge, etc.. And just couldn't find anything really sexy.

For lack of any pre-made solutions, I'll probably cobble together something with Warlock myself. So if I beat you to it, I'll update my answer. :p

2 of 5
28

python-jsonschema-objects is an alternative to warlock, build on top of jsonschema

python-jsonschema-objects provides an automatic class-based binding to JSON schemas for use in python.

Usage:

Sample Json Schema

schema = '''{
    "title": "Example Schema",
    "type": "object",
    "properties": {
        "firstName": {
            "type": "string"
        },
        "lastName": {
            "type": "string"
        },
        "age": {
            "description": "Age in years",
            "type": "integer",
            "minimum": 0
        },
        "dogs": {
            "type": "array",
            "items": {"type": "string"},
            "maxItems": 4
        },
        "gender": {
            "type": "string",
            "enum": ["male", "female"]
        },
        "deceased": {
            "enum": ["yes", "no", 1, 0, "true", "false"]
            }
    },
    "required": ["firstName", "lastName"]
} '''

Converting the schema object to class

 import python_jsonschema_objects as pjs
 import json
 schema = json.loads(schema)   
 builder = pjs.ObjectBuilder(schema)   
 ns = builder.build_classes()   
 Person = ns.ExampleSchema   
 james = Person(firstName="James", lastName="Bond")   
 james.lastName  
  u'Bond'  james      
 example_schema lastName=Bond age=None firstName=James  

Validation :

james.age = -2 python_jsonschema_objects.validators.ValidationError: -2 was less or equal to than 0

But problem is , it is still using draft4validation while jsonschema has moved over draft4validation , i filed an issue on the repo regarding this . Unless you are using old version of jsonschema , the above package will work as shown.

🌐
Built In
builtin.com › software-engineering-perspectives › python-json-schema
How to Use JSON Schema to Validate JSON Documents in Python | Built In
... Summary: The jsonschema library validates JSON data against schemas, utilizing keywords like type, properties, and required. It supports nested objects, arrays, and uses $defs for reusable code.
🌐
PyPI
pypi.org › project › python-jsonschema-objects › 0.0.13
python-jsonschema-objects 0.0.13
October 13, 2014 - JavaScript is disabled in your browser · Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
Find elsewhere
🌐
jsonschema
python-jsonschema.readthedocs.io › en › latest › validate
Schema Validation - jsonschema 4.26.1.dev25+gad0a1b301 documentation
A jsonschema.FormatChecker that will be used when validating format keywords in JSON schemas. ... A function which given a schema returns its ID. ... An object representing the validator’s meta schema (the schema that describes valid schemas in the given version).
🌐
jsonschema
python-jsonschema.readthedocs.io › en › latest › faq
Frequently Asked Questions - jsonschema 4.26.1.dev15+gcbaf0f8fe documentation
Like most JSON Schema implementations, jsonschema doesn’t actually deal directly with JSON at all (other than in relation to the $ref keyword, elaborated on below). In other words as far as this library is concerned, schemas and instances are simply runtime Python objects.
🌐
jsonschema
python-jsonschema.readthedocs.io › en › latest › referencing
JSON (Schema) Referencing - jsonschema 4.26.1.dev25+gad0a1b301 documentation
JSON Schema is defined specifically ... for Python objects which could have possibly existed as JSON. If you stick to the subset of YAML for which this is the case then you shouldn’t have issue, but if you pass schemas (or instances) around whose structure could never have possibly existed as JSON (e.g. a mapping whose keys are not strings), all bets are off. For an example on how to handle that, have a look at the parsers/yaml.py file in the check-jsonschema ...
🌐
DEV Community
dev.to › stefanalfbo › python-json-schema-3o7n
Python JSON schema - DEV Community
May 9, 2024 - In Python we can use the jsonschema library to enable the power of JSON Schema in our projects.
🌐
jsonschema
python-jsonschema.readthedocs.io
jsonschema 4.26.0 documentation
PyPI version Supported Python versions Build status ReadTheDocs status pre-commit.ci status Zenodo DOI jsonschema is an implementation of the JSON Schema specification for Python. It can also be us...
🌐
jsonschema
python-jsonschema.readthedocs.io › en › stable › faq
Frequently Asked Questions - jsonschema 4.26.0 documentation
Like most JSON Schema implementations, jsonschema doesn’t actually deal directly with JSON at all (other than in relation to the $ref keyword, elaborated on below). In other words as far as this library is concerned, schemas and instances are simply runtime Python objects.
🌐
Medium
medium.com › grammofy › handling-complex-json-schemas-in-python-9eacc04a60cf
Handling complex JSON Schemas in Python | by Paul Götze | Grammofy | Medium
August 21, 2020 - In a previous post we looked at how to test your Python API app with JSON Schema. In case you have to deal with complex and nested JSON data, schema definitions can get long and confusing. However, there are ways to clean up and reuse your schemas by using references. Let’s see what they are and how you can leverage them in your testing setup. Let’s take an example endpoint GET /recordings/:id which returns a JSON response for a recording of a classical music piece: We have a work object with a composer and there is a list of recording artists, which include the musicians and technical personnel.
🌐
GitHub
github.com › python-jsonschema › jsonschema
GitHub - python-jsonschema/jsonschema: An implementation of the JSON Schema specification for Python · GitHub
jsonschema is an implementation of the JSON Schema specification for Python. >>> from jsonschema import validate >>> # A sample schema, like what we'd get from json.load() >>> schema = { ... "type" : "object", ... "properties" : { ... "price" ...
Starred by 4.9K users
Forked by 610 users
Languages   Python 99.8% | TypeScript 0.2%
🌐
PyPI
pypi.org › project › genson
genson · PyPI
>>> builder = MinNumberSchemaBuilder() >>> picky_builder = ExclusiveMinNumberSchemaBuilder() >>> picky_builder.add_object(5) >>> picky_builder.to_schema() {'$schema': 'http://json-schema.org/schema#', 'type': 'integer', 'minimum': 5} >>> builder.add_object(None) # this is fine >>> picky_builder.add_object(None) # this fails genson.schema.node.SchemaGenerationError: Could not find matching schema type for object: None ... Clone the repo and make your changes. Make sure your code has test cases written against it. Lint your code with Flake8. Run tox to make sure the test suite passes. Ensure the docs are accurate. Add your name to the list of contributers. Submit a Pull Request. Tests are written in unittest and are run using tox and nose. Tox will run all tests with coverage against each supported Python version that is installed on your machine.
      » pip install genson
    
Published   May 15, 2024
Version   1.3.0
🌐
Pydantic
docs.pydantic.dev › latest › concepts › json_schema
JSON Schema - Pydantic Validation
import json from pydantic import BaseModel, ConfigDict def make_title(model: type) -> str: return f'Title-{model.__name__}' class Person(BaseModel): model_config = ConfigDict(model_title_generator=make_title) name: str age: int print(json.dumps(Person.model_json_schema(), indent=2)) """ { "properties": { "name": { "title": "Name", "type": "string" }, "age": { "title": "Age", "type": "integer" } }, "required": [ "name", "age" ], "title": "Title-Person", "type": "object" } """ Types, custom field types, and constraints (like max_length) are mapped to the corresponding spec formats in the following priority order (when there is an equivalent available): ... The standard format JSON field is used to define Pydantic extensions for more complex string sub-types. The field schema mapping from Python or Pydantic to JSON schema is done as follows:
🌐
PyPI
pypi.org › project › jsonschema-models
jsonschema-models · PyPI
April 8, 2025 - import jsonschema_models as jsm # Create a simple schema schema = jsm.Schema( title='Person', type=jsm.SchemaType.OBJECT, # Or use Python type: type=dict properties={ 'name': jsm.Schema(type=jsm.SchemaType.STRING), # Or use Python type: type=str 'age': jsm.Schema(type=jsm.SchemaType.INTEGER, minimum=0) # Or use Python type: type=int }, required=['name'] ) # Convert to JSON Schema json_schema = schema.model_dump() import jsonschema_models as jsm # Create a schema using specialized classes schema = jsm.ObjectSchema( title='Person', properties={ 'name': jsm.StringSchema(min_length=1), 'age': jsm.
      » pip install jsonschema-models
    
Published   Apr 08, 2025
Version   1.2.3
🌐
JSON Schema
json-schema.org › learn › miscellaneous-examples
JSON Schema - Miscellaneous Examples
The schema below represents a complex object with various properties including name, age, address, and hobbies. The address property is an object with nested properties, and the hobbies property is an array of strings.