Youtilities

JSON to Python Dataclass

Generate Python dataclasses, Pydantic models, or TypedDicts with type hints from any JSON.

Runs in your browser. Nothing is uploaded.

Input

Waiting for JSON

Python
Python types appear here.

What this does

Paste JSON and get Python classes with type hints: @dataclass, Pydantic v2 models, or TypedDict. Nested objects become their own classes, defined before the classes that use them.

Optional and None

A key that is missing from some items, or sometimes null, becomes T | None = None. Dataclass and Pydantic fields with defaults are moved after the required ones, as Python needs. Whole numbers are int, decimals float.

Names

Dataclass and Pydantic fields are snake_case. Pydantic keeps the original key with Field(alias=...); a dataclass has no aliases, so build it from renamed keys yourself. TypedDict keeps the keys exactly and switches to the TypedDict("Name", {...}) form when a key is not a valid identifier.

All