JSON Nerd
A cartoon badger in round glasses, thinking

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 userId become user_id with a Field(alias="userId"), so Root.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