JSON to Dataclass

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.

Options on this page

Output format: @dataclass — Standard-library dataclass with builtin generic type hints.

OptionWhat it does
Root Class NameNames the top-level Dataclass.
Field Naming ConventionOne of snake_case, camelCase, PascalCase, Preserve Original. Defaults to snake_case.
Type for null valuesEither Any or str, used when a key is null in every sample.

How JSON values map to Python types

JSON valuePython type
stringstr
integerint
integer beyond 32 bitsint
decimalfloat
true / falsebool
ISO-8601 timestampdatetime
arraylist[T]
objectnested dataclass
nullAny (configurable)

Example

Input JSON

{
  "id": 12345,
  "product_name": "Wireless Mouse",
  "price": 24.99,
  "in_stock": true,
  "tags": ["electronics", "accessories"],
  "manufacturer": {
    "name": "Acme Corp",
    "country": "US"
  }
}

Generated Python

from dataclasses import dataclass

@dataclass
class Product:
    id: int
    product_name: str
    price: float
    in_stock: bool
    tags: list[str]
    manufacturer: Manufacturer

Frequently asked questions

Which Python version does the output require?

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.

Why are my JSON keys renamed?

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".

Is my JSON uploaded anywhere?

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.

Does it cost anything?

No. The generator is free to use with no sign-up and no usage limits.

How are nested objects handled?

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.

Other languages