Skip to main content

JSON to Python Class

Convert JSON to Python Pydantic v2 models, dataclasses or TypedDicts with type hints, aliases for camelCase keys and datetime/UUID detection.

100% client-side · no data leaves your browser

Pydantic parses them for you

Python — 3 types
from datetime import datetime
from typing import Any

from pydantic import BaseModel, Field


class Address(BaseModel):
    street: str
    city: str
    zip_code: str = Field(alias="zipCode")


class Order(BaseModel):
    order_id: str = Field(alias="orderId")
    total: float
    items: int
    shipped: bool
    coupon: str | None = None


class Root(BaseModel):
    id: int
    username: str
    email: str
    is_active: bool = Field(alias="isActive")
    rating: float
    created_at: datetime = Field(alias="createdAt")
    avatar_url: Any = Field(alias="avatarUrl")
    tags: list[str]
    address: Address
    orders: list[Order]

Arrays of objects are merged: a key missing from some items becomes optional, null makes a field nullable, and identical shapes share one type. Paste several examples in an array for the most accurate types.

About this tool

Paste JSON and get typed Python models. Choose Pydantic v2 BaseModel (fields in snake_case with Field(alias=…) for keys like createdAt, plus datetime, date and UUID types that Pydantic parses for you), standard-library dataclasses, or TypedDict for annotating plain dicts. Optional keys become X | None = None (or NotRequired in a TypedDict), nested objects become their own classes defined before they're used, lists become list[T] and ID-keyed objects become dict[str, T]. Python keywords and Pydantic's own method names are renamed safely. Imports are grouped like isort and spacing follows Black. Switch to Go, Rust, C# or Kotlin from the same page.

How to convert JSON to Python models

Generate Pydantic models or dataclasses from JSON.

  1. 1

    Paste JSON

    Paste a JSON object, or an array of examples.

  2. 2

    Pick a style

    Choose Pydantic, dataclasses or TypedDict.

  3. 3

    Copy the code

    Copy the classes or download models.py.