JSON to Python Dataclass
Turn a sample JSON object into a typed Python @dataclass.
Type a JSON payload in Python
Turning an API response into a typed Python class is repetitive work. This tool reads a sample JSON object and generates a @dataclass with a field and type hint for each key, ready to paste into your code.
A record with an id, name, active flag, and a list of tags becomes a dataclass with int, str, bool, and list fields. Numbers, booleans, strings, lists, and objects are each mapped to a sensible Python type.
A fast start, kept private
It infers the class in your browser and never uploads your JSON. Refine nested types by hand where you want stricter hints.
Frequently Asked Questions
What types does it use?
It maps JSON values to Python hints: int, float, bool, str, list, and dict, based on the sample values you provide.
Does it handle nested objects?
Nested objects are typed as dict for simplicity; you can split them into their own dataclasses afterward if you prefer.
Which Python version?
The @dataclass decorator needs Python 3.7 or newer, which covers all current versions.
Browse the full set of free, private, in-browser tools.