Skip to content
ToolMug

JSON to Pydantic Model Converter

Paste JSON and get Pydantic models you can use to validate and parse data in Python. Keys become snake_case attributes with aliases to the original names, and nested objects become their own classes.

Runs in your browser — nothing you enter is uploaded

How to use

  1. Paste a JSON sample, or click Load sample.
  2. Set the name of the root model.
  3. Copy or download the generated code.

Options explained

Root type name
Name of the top-level model class. Nested classes are named after their keys.

Examples

{"userName": "ada", "age": 36} becomes:

class Root(BaseModel):
    user_name: str = Field(alias="userName")
    age: int

Frequently asked questions

Which Python and Pydantic versions does it target?

Pydantic v2 with Python 3.10 or later, using list[str] and str | None annotations.

How do I parse data that uses the original key names?

Fields whose names were changed have an alias, so Root.model_validate(data) accepts the original keys such as userName. To also accept the Python names, set populate_by_name in the model config.

What happens with keys that are Python keywords?

An underscore is added, so a key named class becomes the attribute class_ with alias "class".

Is my JSON uploaded?

No. The types are generated in your browser, so API responses with real data stay on your device.

Privacy

This tool runs entirely in your browser. Your files and text are processed on your device and are never uploaded to our servers.

Related tools