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-converterVerified import paths — ran on the pinned version, not inferred.
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.
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()`.
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.
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).