Turn a JSON sample into Python dataclasses, Pydantic models or TypedDicts with type hints
Runs in your browser. Nothing you type is sent anywhere. Checked against sources on 16 Oct 2026.Paste a JSON sample and get Python dataclasses, Pydantic v2 models or TypedDicts with type hints. Whole numbers become int and any decimal makes a field float; a value that is null or missing becomes str | None with None as its default, and 3 class styles share the same inference.
Paste a JSON sample, such as an API response, into the left box.
The Python classes appear as you type: one class per object, with type hints such as int, float, list[str] and str | None.
Choose dataclass, Pydantic or TypedDict, and Python 3.9 typing if your project is older than 3.10.
Press Copy, or Download to save models.py.
Python reads JSON into dictionaries, and a class with type hints is what lets an editor, a type checker or Pydantic catch a misspelt key or a wrong type. This converter writes those classes from a sample, so a long API response becomes typed Python in one paste.
How types are chosen.
| JSON value | Python type |
|---|---|
| "text" | str |
| true / false | bool |
| 42 (whole numbers only) | int |
| 4.5 (any decimal seen) | float |
| null, and also a type | str | None, or Optional[str] |
| only null, or mixed kinds | Any |
| [ ... ] | list[...] |
| { } empty | dict[str, Any] |
| { ... } | a class of its own |
Arrays of objects. All the objects of an array are merged into one class, so a key that appears in only some of them is still there, typed to allow None and given None as its default. Two objects with exactly the same keys and types share one class.
Three styles. A dataclass needs nothing installed; fields with a default are moved after the others, because Python raises a TypeError otherwise. Pydantic models use snake_case attributes with Field(alias=...) for keys spelt differently, such as userName or first-name. A TypedDict keeps the keys exactly and marks the occasional ones NotRequired.
Order and names. Classes are written children first, so every name is defined before it is used. A keyword such as class becomes class_, and a key that would hide a type, such as list, gets the same underscore.
Every style was checked by running the output under CPython with Pydantic 2 and validating the sample. Nothing you paste leaves the browser.
Paste a JSON sample into the converter and the Python classes appear beside it, one per object, with a type hint on every attribute. Choose dataclass for plain classes, Pydantic for validation, or TypedDict to keep working with ordinary dictionaries, then copy the module into your project.
A dataclass suits data you build yourself and needs no library. Pydantic suits data from outside, such as API responses, because it checks every value and converts nested objects for you. A TypedDict only adds type hints to the dictionary json.loads returns, so it costs nothing at runtime.
Pydantic attributes are written in snake_case, as PEP 8 asks, with Field(alias="userName") so validation still reads the original key. A TypedDict keeps every key exactly, switching to the functional syntax when a key is not a valid name. A dataclass keeps keys that are valid names and notes the rest.
A key that was null in the sample, or missing from some objects of an array, can hold None, so its hint allows it. Missing keys also get None as the default, and in a dataclass those fields move to the end, because Python refuses a field without a default after one with a default.
The default typing, such as list[str] and str | None, needs Python 3.10 or later. Switch on Python 3.9 typing to get Optional and List from the typing module instead. NotRequired for TypedDict comes from typing_extensions, and is in typing itself from Python 3.11.
No. The conversion runs in your browser with no request to any server, and the JSON is not stored, so API responses holding tokens or personal data stay on your device. Close the tab and nothing remains.
Rates and rules change; check the source before you rely on a figure.
Still stuck? Ask about JSON to Python Class Converter and anybody who knows can answer. No account needed.
Same job, other tools: TSV to JSON – Convert tab-separated values, such as a paste from Excel, into JSON · JSON to YAML – Turn JSON into clean, readable YAML for configs · Query String Parser – Split a URL query string into a table of decoded parameters.