
JSON to Python
Turn a JSON sample into Pydantic models, dataclasses or TypedDicts.
Runs in your browser. Nothing you type is uploaded.
How the converter works
Paste a JSON sample and the Python appears as you type. Choose a Pydantic model, adataclass or a TypedDict. Nested objects become their own classes, defined before they are used so the code runs top to bottom.
The three styles
- Pydantic validates and parses data. Keys such as
userIdbecomeuser_idwith aField(alias="userId"), soRoot.model_validate(data)still works. - dataclass is plain standard library. Fields with defaults are placed last, as Python requires, and a comment records any renamed JSON key.
- TypedDict describes the dictionary you get from
json.loads, with no conversion. Keys that are not valid identifiers use the functional syntax.
How types are chosen
Numbers become int or float, text becomes str, and arrays become list[...]. A value that can be null becomes X | None, and fields missing from some array items default to None (or NotRequiredin a TypedDict). Different types in the same place become a union, so [1, "a"] giveslist[int | str]. Empty arrays become list[Any].
FAQ
Which Python version do I need?
The output uses X | None and list[int], so Python 3.10 or newer. TypedDict's NotRequired needs 3.11, or typing_extensions on older versions.
Can a dataclass load JSON directly?
Not by itself. Python's dataclasses do not convert dictionaries, so use Pydantic if you want parsing and validation built in.
Is my JSON sent anywhere?
No. The conversion runs in your browser, so your data stays on your device.
More JSON tools
- JSON formatter: Format, minify and validate JSON in one place.
- JSON validator: Check JSON syntax and find the exact line and column of an error.
- JSON beautifier: Pretty print JSON with 2 spaces, 4 spaces or tabs.
- JSON minifier: Strip whitespace to make JSON as small as possible.
- JSON to Go struct: Generate Go struct definitions with json tags from a JSON sample.
- JSON to TypeScript: Generate TypeScript interfaces or types from a JSON sample.
- JSON to Rust: Generate Rust structs with serde derives from a JSON sample.