Convert JSON to Python dataclasses with type hints
Paste JSON and get Python dataclasses back instantly. Every field carries a type hint inferred from the data, nested objects become their own dataclasses, and the required imports are collected at the top of each file. Field names default to snake_case so the result reads like hand-written Python.
Output format: @dataclass — Standard-library dataclass with builtin generic type hints.
| Option | What it does |
|---|---|
| Root Class Name | Names the top-level Dataclass. |
| Field Naming Convention | One of snake_case, camelCase, PascalCase, Preserve Original. Defaults to snake_case. |
| Type for null values | Either Any or str, used when a key is null in every sample. |
| JSON value | Python type |
|---|---|
| string | str |
| integer | int |
| integer beyond 32 bits | int |
| decimal | float |
| true / false | bool |
| ISO-8601 timestamp | datetime |
| array | list[T] |
| object | nested dataclass |
| null | Any (configurable) |
{
"id": 12345,
"product_name": "Wireless Mouse",
"price": 24.99,
"in_stock": true,
"tags": ["electronics", "accessories"],
"manufacturer": {
"name": "Acme Corp",
"country": "US"
}
}
from dataclasses import dataclass
@dataclass
class Product:
id: int
product_name: str
price: float
in_stock: bool
tags: list[str]
manufacturer: Manufacturer
Python 3.9 or newer. Lists are annotated with the builtin generic form list[str] rather than typing.List[str], which requires 3.9+. The @dataclass decorator itself has been available since Python 3.7.
Field names default to snake_case because that is what PEP 8 asks for, so a JSON key productName becomes product_name. If your deserializer matches on the exact JSON key, switch Field Naming Convention to "Preserve Original".
No. Parsing, type inference, and code generation all run in your browser using JavaScript. Your JSON is never sent to a server, and there is no account, tracking, or storage beyond your own browser.
No. The generator is free to use with no sign-up and no usage limits.
Each nested JSON object becomes its own named type, derived from the key it appeared under. Arrays of objects are widened across every element, so a field that is a whole number in one element and a fraction in another gets a type that holds both.