Tools
Get Pro

JSON to Pydantic

Paste JSON — get Pydantic models as you type. Nothing leaves your browser.

to
JSON
Loading the converter…
Pydantic options
› More options & type detection

JSON to Pydantic example

Turn an API response into Pydantic models for FastAPI, LangChain or any typed Python code. Each object becomes a BaseModel subclass, nested objects get their own model, and fields missing from some items become Optional.

JSON input
{
  "id": 1001,
  "status": "paid",
  "total": 42.5,
  "currency": "EUR",
  "customer": {
    "name": "Ada Lovelace",
    "email": "ada@example.com"
  },
  "items": [
    {
      "sku": "pen",
      "qty": 3,
      "price": 1.5
    },
    {
      "sku": "notebook",
      "qty": 1,
      "price": 4,
      "gift_wrap": true
    }
  ],
  "created_at": "2026-11-01T10:00:00Z"
}
Generated Pydantic — default settings, type name Order
from pydantic import BaseModel
from typing import Optional, List


class Customer(BaseModel):
    name: str
    email: str


class Item(BaseModel):
    sku: str
    qty: int
    price: float
    gift_wrap: Optional[bool] = None


class Order(BaseModel):
    id: int
    status: str
    total: float
    currency: str
    customer: Customer
    items: List[Item]
    created_at: str
One model per object
The root becomes Order, the nested customer becomes its own model, and the items array becomes a list of Item models. Pydantic builds the whole tree from a dict: Order(**data) or Order.model_validate(data).
Optional fields
gift_wrap appears in only one item, so it is Optional with a None default. Paste several samples (one per line, or an array of responses) to get the optional fields right.
Dates and numbers
created_at comes out as str. Change it to datetime (from datetime import datetime) and Pydantic parses the ISO string for you. price is a float because 1.5 has a fraction, even though 4 is whole; qty stays int.
Python version
The default targets Python 3.7 (Optional, List). Choose 3.9 or 3.10 under options for list[str] and str | None, as used by Pydantic v2 projects.

Types that match your real data

Built on the open-source quicktype engine, with quieter defaults and a friendlier editor.

Optional fields detected
Fields that are missing or null in some items become optional automatically.
Merge many samples
Paste JSON Lines or an array — every example contributes to one accurate type.
Paste anything
JavaScript objects, trailing commas, single quotes and comments are repaired for you.
Sensible defaults
No surprise enums or date classes — turn detection on only when you want it.
Every option, every language
All of Pydantic’s generator settings, from naming style to framework annotations.
Private & instant
Runs in a background thread in your browser. Share links keep data in the URL only.

Frequently asked questions

How do I convert JSON to a Pydantic model?+

Paste your JSON, set the root model name under Type name, and copy the generated classes into a .py file. Load data with Order.model_validate(data) in Pydantic v2, or Order.parse_obj(data) in v1.

Does it work with Pydantic v2?+

Yes. The models subclass BaseModel with plain type hints, which both v1 and v2 accept. Choose Python 3.10 for the modern str | None syntax.

What about camelCase keys like displayName?+

By default names are made Pythonic (display_name). Pydantic then needs an alias to read displayName, so turn off “Transform property names to be Pythonic” to keep the JSON names exactly.

What if my samples have different fields?+

Paste several samples as JSON Lines (one JSON value per line) or as an array of objects. They are merged into one type, and fields missing from some samples become optional.

Can I paste a JavaScript object from the console?+

Yes. Unquoted keys, single quotes, trailing commas and comments are repaired automatically before the types are generated.

Is my data uploaded?+

No. The conversion runs entirely in your browser, in a background thread. Nothing is sent to a server.

Why don’t I see enums or date types?+

By default, string fields stay strings so the output matches your JSON exactly. Turn on “Detect enums” or “Detect dates” under Options to generate enum and date types.

Code generation uses quicktype (Apache-2.0 license).