Formatter Validator Minifier Escape / Unescape JSON ↔ String JSON ↔ YAML JSON → CSV NDJSON / JSON Lines JSON → Types JSON ↔ XML JSON Diff JSON Patch Canonicalize (RFC 8785) Schema Validator Schema Generator JSONPath Tester JWT Decoder JSON Errors Schemas More Tools
● PYDANTIC MODELS · 100% BROWSER-BASED

JSON to Pydantic

Paste a JSON sample and get Pydantic models, instantly and entirely in your browser. Optional fields, nullability and nested types are inferred from the sample — and anything the sample cannot settle is reported rather than guessed.

JSON sample
TypeScript interface
Type definitions will appear here

Pydantic models from a sample

Generates BaseModel classes with ConfigDict(populate_by_name=True) and a Field(alias=...) wherever the JSON key had to be renamed, so the model round-trips by alias.

Verified by importing the generated module and validating a real sample against it.

What a sample cannot tell you

Types are inferred from one sample. A field absent from your sample will be absent from the output, and a field that happens to hold only whole numbers will be typed as an integer even if it can hold decimals. Paste the widest sample you have. For a guarantee rather than an inference, start from a JSON Schema.

What Pydantic output looks like

Generated from two sample records, one of which has an extra field and a null. This is the actual output, not an illustration:

from typing import Any, List, Optional

from pydantic import BaseModel, ConfigDict, Field


class Address(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    city: str
    postcode: Optional[Any] = None


class Root(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    id: int
    user_name: str = Field(..., alias="userName")
    is_active: bool = Field(..., alias="isActive")
    score: float
    tags: List[str]
    address: Address
    last_seen: str = Field(..., alias="lastSeen")
    nickname: Optional[str] = None

The three things that differ by language

Large integers

Python integers are arbitrary precision, so large identifiers survive. Pydantic v2 validates on construction, so a wrong type fails at the boundary rather than deep in your code.

Optional against nullable

Absent fields become Optional[T] = None. Because Pydantic distinguishes "not provided" from "provided as null", the generated model reflects what the samples actually showed.

Names that are not identifiers

Field(alias=...) is emitted wherever a key had to be renamed, with populate_by_name=True, so the model accepts either name and round-trips by alias.

Convert the same JSON to