Registry / serialization / jsonschema-pydantic-converter

jsonschema-pydantic-converter

JSON →
library0.4.0pypypi✓ verified 83d ago

This library dynamically converts JSON Schema definitions into Pydantic models at runtime. It currently supports both Pydantic v1 and v2. The latest version is 0.4.0, with development actively progressing through minor releases.

pip install jsonschema-pydantic-converter
INSTALL
IMPORT
SIG · JSONSCHEMA-PYDANTI
J
jsonschema-pydantic-converter
serializationpythonv0.4.0
Install
3.0s avg
Import
Disk
26MB
Pass rate
8/ 10
Env Coverage8 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.4.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✓ —
✓ 3.83s
py 3.11
✓ —
✓ 3s
py 3.12
✓ —
✓ 2.55s
py 3.13
✓ —
✓ 2.65s
py 3.9
✕ build_error
✕ build_error
26MB installed
● package 26MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

create_type_adapter
from jsonschema_pydantic_converter import create_type_adapter
from jsonschema_pydantic.builder import build_pydantic_model
transform
from jsonschema_pydantic_converter import transform
transform_with_modules
from jsonschema_pydantic_converter import transform_with_modules

This quickstart demonstrates how to define a simple JSON Schema, use `build_pydantic_model` to generate a Pydantic model dynamically, and then instantiate and validate data against the newly created model. It also shows an example of a validation failure.

from jsonschema_pydantic.builder import build_pydantic_model # Define a JSON Schema schema = { "title": "User", "type": "object", "properties": { "name": {"type": "string", "minLength": 1}, "age": {"type": "integer", "minimum": 0, "maximum": 150}, "email": {"type": "string", "format": "email"} }, "required": ["name", "age"] } # Build the Pydantic model from the schema UserModel = build_pydantic_model(schema_data=schema) # Instantiate and use the generated model try: user_data = UserModel(name="Alice", age=30, email="alice@example.com") print("Valid user data:") print(user_data.model_dump_json(indent=2)) except Exception as e: print(f"Error creating valid user: {e}") # Demonstrate validation failure try: invalid_user_data = UserModel(name="", age=-5) print("Invalid user data (should not reach here):", invalid_user_data) except Exception as e: print("\nValidation error for invalid user data:") print(e)
Debug
Known issues
gotchaWhile the library supports both Pydantic v1 and v2, the behavior of the *generated* models (e.g., method names like `.dict()` vs `.model_dump()`, specific validator implementations) can differ. Ensure your application's Pydantic version aligns with the expected model behavior.
fix
Always test generated models with your target Pydantic version. For Pydantic v1, use `.dict()` and `.json()`. For Pydantic v2, use `.model_dump()` and `.model_dump_json()`.
affects: All versions
gotchaThe library relies on well-formed and compliant JSON Schema definitions. Malformed schemas, unsupported keywords, or custom extensions not handled by the library can lead to conversion errors or unexpected Pydantic model structures.
fix
Validate your JSON Schema externally (e.g., using `jsonschema.validate`) before passing it to `build_pydantic_model`. Refer to the official JSON Schema specification for valid syntax and keywords.
affects: All versions
gotchaSchemas with deeply nested or complex `$ref` references, especially those involving circular dependencies or external files, might encounter resolution issues or performance degradation.
fix
Simplify complex `$ref` structures where possible. Ensure all referenced schemas are accessible and well-defined. For external `$ref`s, ensure the converter's environment can resolve them (though current versions focus on in-schema refs).
affects: All versions
Upgrade
Version history
0.4.0latest on PyPI · released Mar 25, 2026
Audit
Dependencies
pydanticrequiredCore dependency for generating and validating models.
jsonschemarequiredCore dependency for parsing and validating JSON schemas.
Agent activity
2 hits · last 30 days
node
2
Resources
jsonschema-pydantic-converter — pip install jsonschema-pydantic-converter · libregistry