DeveloperAdded
JSON to Python Dataclass
Turn a JSON sample into Python dataclasses with real type hints. Nested objects become their own class, arrays become lists, and nulls stay optional.
Generate Python dataclasses
210 / 232Result
WaitingRun the tool and the result appears here. Copy it or download it — nothing leaves this tab.
Privacy
API samples often contain tokens and user data. They are parsed in this tab and never sent anywhere.
How to use it
Paste one JSON object or array. A representative sample is enough — one array element.
Set the root class name if you want something other than Root.
Copy the dataclasses. Nested objects are emitted as separate classes, in alphabetical order.
When to use it
Typed API clients
Sketch the response model before you write the client, so the field names and nullability are decided once.
Test fixtures
Turn a captured payload into a dataclass you can construct in tests without a dict of magic strings.
Data scripts
Give a quick ETL script real types so an editor can catch a renamed field.
Questions
Why dataclasses and not Pydantic?
Dataclasses are in the standard library, so the output runs anywhere without a dependency. Converting a dataclass to a Pydantic model is a one-line change if you need validation.
How are null values handled?
A JSON null becomes Optional[Any] with a None default. That is deliberately loose: JSON has no type information, so guessing a concrete type would be wrong.
What happens to keys that are not valid Python names?
They are snake-cased, and names that collide with a Python keyword get a trailing underscore.
Does it handle arrays of objects?
Yes. The first element decides the type, so make sure the sample is representative of the whole array.