You are offline. Tools you have opened before keep working.
JSON to Python classes
Paste JSON and get Python dataclasses, Pydantic models or TypedDict definitions with full type hints. Optional fields default to None and keys are converted to snake_case.
Free and private. Everything runs in your browser, nothing is uploaded.
Report a problem
How it works
Paste your JSONPaste a response from your API or open a .json file. Use Sample to see an example.
Adjust the optionsSet the name of the top level type and the options for this language. The code updates as you type.
Copy or downloadCopy the code into your project or download it as a file.
Three styles for three jobs
Dataclasses are part of the standard library and are a good fit for internal data. Pydantic models validate and convert data when you load it, and the generator adds Field(alias=...) whenever the Python name differs from the JSON key, so model_validate reads the original data. TypedDict only describes the shape of a dictionary, which is handy when you keep working with the output of json.loads; keys that are not valid Python names use the functional TypedDict syntax.
Optional fields are moved to the end of each dataclass, because Python requires fields with a default value to come after the others. Types use the modern list[...] form, so the code needs Python 3.9 or later; NotRequired in TypedDict needs Python 3.11 or typing_extensions.
Frequently asked questions
Why does the code start with from __future__ import annotations?
It lets classes refer to each other in any order and keeps the annotations as written. It is safe with dataclasses and Pydantic 2.
Is my JSON uploaded anywhere?
No. The types are generated in your browser. API responses with customer data or keys never leave your device.
How are optional fields detected?
If the JSON contains a list of objects, every object is compared. A field that is missing from at least one object is marked optional. With a single object, every field is treated as required.
What happens with fields that are always null?
The type cannot be known from the sample, so the field gets a general type such as unknown, object, Any or JsonElement. Add a sample where the field has a value to get a precise type.
Why is my 1.0 typed as a decimal number?
The tool looks at how the number is written. 1.0 or 2.5 become double or float, 1 becomes an integer. If a field is whole in some items and decimal in others, the decimal type is used.
Can I use the result in production code?
Yes, the code compiles as it is in the usual setups. Review names and types before you commit it, because a sample can never show every possible value.
Does it work offline?
Yes. After you open the page once, it keeps working without an internet connection.