JSON Schema to Pydantic converter

Convert JSON Schema to Pydantic v2 models: a BaseModel per object, Literal for enums, Field constraints, aliases for keys that are not Python names, nested and recursive models, and validators for oneOf, if/then/else, not, dependencies and contains.

JSON Schema

Pydantic

Waiting for input

What you get

How each result is checked

  1. The models are run with the real pydantic 2 in your browser (CPython compiled to WebAssembly), not just generated.
  2. Your examples, plus valid and broken test values built from the schema, are validated by pydantic (strict JSON mode) and by a reference JSON Schema validator (Ajv). They must agree.
  3. Where pydantic is documented to differ (listed in the notes, for example patternProperties), only those exact rules are relaxed when comparing; any other difference fails the check.

What can't convert exactly

  • Optional properties that are not nullable become `Omittable[X] = None`: they may be left out, but null is rejected, as in JSON Schema. Prefer plain `X | None = None`? Choose "Simple" in the options (the model then also accepts null, and the notes say so).
  • oneOf, if/then/else, not, dependentRequired, dependentSchemas and contains are checked by small validators in the generated module (oneOf: exactly one branch must match). A Union is left as it is when its branches cannot overlap.
  • patternProperties, propertyNames and minProperties/maxProperties on models are not checked; the notes name them when your schema uses them.
  • Checks use strict validation. In pydantic's default (lax) mode it also converts some inputs, for example "1" to 1.
  • The first run downloads Python and pydantic (about 6 MB compressed), once.

Questions

Which Python and pydantic versions?

The code targets Python 3.10+ and Pydantic 2. It is checked with pydantic 2.14 on Python 3.14.

How exact is it on real schemas?

The test suite runs every schema in SchemaStore through pydantic and a reference validator on generated data; the accuracy page lists the results.

Why are some fields `Annotated[...]`?

Constraints such as min_length, pattern, ge and le go into Field() inside Annotated, so they also apply inside lists and unions.

Do I need to install a code generator to convert JSON Schema to Pydantic?

Nothing to install: no package, CLI or account. It runs in your browser, so you can try a schema before adding a generator to your build.

Does it generate Pydantic v1 or v2 code?

Pydantic v2: BaseModel classes with Annotated types and Field(...) rules, and model validators where the schema needs them. Pydantic v1 works differently, so the code needs Pydantic 2.

How do I convert JSON Schema to Pydantic online?

Paste your JSON Schema or open a file on the left (or click Example). The Pydantic appears on the right as you type, already checked. Copy it, or download it as a file. Nothing is uploaded.

Can the Pydantic output be wrong?

Every result is checked before it is shown (the checks are listed on this page). If a check fails, the page says "Review needed" and why, instead of presenting the output as correct, and anything that cannot convert exactly is named in the notes.