skillfed

json-schema-to-pydantic

A Python library for automatically generating Pydantic v2 models from JSON Schema definitions

json-schema-to-pydantic v0.4.11 2.1M downloads/30d#3,293 on PyPI46
Permissive license MIT Active released

What it is and what it does

json-schema-to-pydantic bridges JSON Schema and Pydantic by generating type-safe Pydantic v2 models directly from schema definitions. It handles the complexity of schema features—$ref resolution with circular reference detection, combiners like allOf/anyOf/oneOf, format validations (email, uri, uuid, date-time), and edge cases like underscore-prefixed fields common in OpenAPI specs—so you don't have to write model classes by hand.

The library exposes a simple `create_model()` function for straightforward cases and a lower-level `PydanticModelBuilder` for advanced scenarios where you need to inject predefined models or type aliases. It supports relaxed validation modes for schemas that omit type information, and it generates models with full type hints. The package requires Python 3.9+ and depends only on pydantic.

Use it for:

  • Convert OpenAPI/Swagger specs to Pydantic models for API client or server validation
  • Automatically generate data models from JSON Schema files in data pipelines
  • Build form validators from schema definitions without manual model coding
  • Validate incoming JSON payloads against a schema-derived Pydantic model
  • Integrate schema-driven APIs with Python codebases that use Pydantic for type safety

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Automatically generates Pydantic v2 models from JSON Schema definitions, handling references, combiners, validations, and format constraints.

Yes. The package is actively maintained, has no known vulnerabilities, low install friction, and solves a real problem—eliminating boilerplate when you already have a JSON Schema. It's especially valuable if you work with OpenAPI specs or schema-heavy APIs. The MIT license is permissive. The single dependency on pydantic is a strength, not a weakness, since pydantic is ubiquitous.

Install

json-schema-to-pydantic on PyPI

pip

pip install json-schema-to-pydantic

uv

uv add json-schema-to-pydantic

poetry

poetry add json-schema-to-pydantic

Installing json-schema-to-pydantic

Before you install

Low friction: pure Python wheel with a single runtime dependency on pydantic. Active maintenance with recent commits and no known vulnerabilities.

License in practice

MIT license permits commercial and private use with minimal restrictions—suitable for most projects.

Quickstart

pip install json-schema-to-pydantic

from json_schema_to_pydantic import create_model

schema = {
    "title": "User",
    "type": "object",
    "properties": {
        "name": {"type": "string"},
        "email": {"type": "string", "format": "email"}
    },
    "required": ["name", "email"]
}

UserModel = create_model(schema)
user = UserModel(name="John", email="john@example.com")

Verify before relying

  • Performance characteristics with very large or deeply nested schemas
  • Completeness of JSON Schema draft version support (draft 7, 2020-12, etc.)
  • Behavior when predefined_models or predefined_refs contain conflicting definitions

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.9)
Install friction low — pure-Python wheel
Runtime dependencies 1 — pydantic
Maintenance actively maintained — 158 days since the last release
Last repo commit
First released
Downloads 2,105,875/month — #3,293 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: json_schema_to_pydantic-0.4.11-py3-none-any.whl

Keywords: conversion, json-schema, pydantic, schema, validation

Development Status :: 4 - BetaIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Topic :: Software Development :: Libraries :: Python ModulesTyping :: Typed

Tags

json schema to pydanticgenerate pydantic models from schemajson schema validationpydantic model generationschema to python modelsopenapi to pydanticjson schema converter
schema-generationopenapidata-validation

More Python Modules packages