{ } JSON Workbench0 network requests. Check DevTools

"JSON to Pydantic":{ }

Paste a JSON sample and get clean Pydantic models. Nested objects become named types, arrays become typed collections, and nullable fields are handled. Powered by quicktype's inference engine running 100% in your browser: zero network requests, so real API payloads stay on your machine.

What is a JSON to Pydantic converter?

Hand-writing models for an API response is slow and error-prone. This tool infers Pydantic models from a JSON sample: nested objects become named types, arrays become typed collections, and null/missing values become optional fields. It runs quicktype's inference engine entirely in your browser, so real API payloads (often containing user data or credentials) never leave your machine.

Pydantic mapping notes

  • Each nested object becomes its own BaseModel subclass, referenced by the parent.
  • Missing or null fields become Optional[...] = None; arrays become List[...] (arrays of objects → List[Model]).
  • Output is idiomatic Pydantic, with no hand-written parsing. Validation and coercion happen automatically when you construct the model (e.g. Root(**data)).

How to use

  1. Paste a JSON sample (an API response works well) into the Input pane.
  2. Generated Pydantic models appear instantly. Nested objects become their own named types.
  3. Non-standard JSON (single quotes, trailing commas, comments) is auto-repaired first.
  4. Copy the code into your project.

Examples

JSON → Pydantic models

Input
{
  "id": 42,
  "name": "workbench",
  "owner": { "email": "[email protected]", "active": true }
}
Output
from pydantic import BaseModel


class Owner(BaseModel):
    email: str
    active: bool


class Root(BaseModel):
    id: int
    name: str
    owner: Owner

FAQ

How do I convert JSON to Pydantic types?

Paste any JSON sample. The models are inferred from the values and nesting, entirely in your browser. Nothing is uploaded.

How are nested objects handled?

Each distinct nested object becomes its own named type, referenced from the parent, arrays of objects included.

What about optional or null fields?

Fields that are null or missing in parts of the sample are typed as optional/nullable in the generated code.

Can I paste multiple samples?

Paste an array of objects: the type is inferred from the union of all items, which catches optional fields a single sample would miss.

Does this target Pydantic v1 or v2?

The generated classes are plain BaseModel subclasses that work with both Pydantic v1 and v2. On v2 you can optionally switch List[...] to the built-in list[...].

Is my JSON uploaded?

No. Generation runs 100% in your browser via quicktype's engine. Check DevTools: zero network requests.

Related tools