JSON to Python Dataclass Converter
Turn a JSON object into Python @dataclass definitions with type hints, in your browser.
How to use
- Paste or type your JSON into the input box.
- Optionally rename the root class (defaults to AutoGenerated).
- Copy the generated dataclasses from the output box.
- Take the typing import line above the classes as well — the dataclasses will not type-check without it.
About this tool
ShowHide
Paste any JSON object or array and get ready-to-use Python @dataclass definitions with type hints, plus the matching typing import line. Nested objects become their own dataclasses named after the key that held them, and arrays are typed from their first element, so a list of objects turns into List[Item] rather than a bare list. Two cases produce Any on purpose: a JSON null, whose real type cannot be known from one sample, and an empty array, which gives List[Any]. Because the shape is inferred from one document, an optional field that happens to be missing or null in your sample will need Optional added by hand. Everything runs locally in your browser — your JSON is never uploaded.
Frequently asked questions
How are numbers typed?
Whole numbers become int and numbers with a decimal point become float. Adjust manually if you need a different type.
What happens with null or empty arrays?
null values map to Any and empty arrays to List[Any], since their type can't be inferred from the sample.
How are nested objects handled?
Each nested object becomes its own @dataclass, defined before the class that references it.
Is my JSON sent anywhere?
No. Conversion happens entirely in your browser; nothing is uploaded.
Why is every field required?
The shape is inferred from the one document you pasted, which cannot show which keys the server sometimes omits. Wrap those fields in Optional and give them a default yourself.
Do these dataclasses validate the data?
No. A dataclass accepts whatever you construct it with — the type hints are for your editor and type checker, not enforced at runtime. If you need parsing that rejects bad input, feed the same shape to pydantic instead.
Related tools
JSON to GraphQL Schema (SDL) Converter
Turn a JSON object into GraphQL type definitions (SDL) with scalar mapping, in your browser.
Developer
JSON → TypeScript Interface
Generate TypeScript interfaces from any JSON sample — types are inferred recursively and named after each key.
Developer
.gitignore Generator
Tick the languages, frameworks, editors, and operating systems you use — get one combined .gitignore ready to drop into a fresh repo.
Developer
Python Pickle Inspector
Disassemble a .pkl file in the browser: every opcode, the memo, the value it rebuilds, and whether loading it would run code.
Developer
Python .pyc Bytecode Inspector
Open a .pyc from __pycache__ in your browser: which CPython wrote it, timestamp or hash invalidation, the code object tree and the disassembly.
Developer
MIME Type Lookup
Find the MIME type for a file extension (or the other way around) and learn what each type is for.
Developer