Generate @dataclass or TypedDict classes from JSON. Free, private, runs in your browser.
100% private — your files never leave your browser. All processing happens locally on your device.
Python has two idiomatic ways to model structured data with types. `@dataclass` (from `dataclasses`) gives you a real class with default values, `__init__`, `__repr__`, and equality — the right choice when the data is a first-class domain object you'll mutate, compose, and pass around. `TypedDict` (from `typing`) is a structural type hint for plain dictionaries — zero runtime overhead, still a plain `dict`, but your type checker now knows the keys and their types. Pick TypedDict when you receive JSON from an API and want typed access to a dict; pick dataclass when you want a real Python object.
Strings become `str`, booleans become `bool`. Whole numbers become `int`, decimals become `float`. Null values in the sample emit `Optional[Any]` — a deliberate choice so the type hint doesn't pretend to know the shape of values that were never provided. Homogeneous arrays become `List[T]`; heterogeneous or empty arrays become `List[Any]`. Nested objects get their own class, referenced from the parent field.
The output always starts with the appropriate imports — `dataclass` and `field` for dataclass mode, `TypedDict` for typeddict mode, plus `List`, `Optional`, `Any`, and `Dict` from typing. Dataclass fields get sensible defaults: `List` fields use `field(default_factory=list)`, `Dict` fields use `field(default_factory=dict)`, optionals default to `None`. Python reserved words (`class`, `for`, `import`, `return`, etc.) get a trailing underscore in the emitted field name to stay syntactically valid.
Inference from a single sample has limits. If a field sometimes appears and sometimes doesn't, the emitted class won't know — mark that field `Optional[T]` manually. If two different sample responses have different types for the same field, you need a union (`Union[int, str]`) that one sample couldn't reveal. Use the output as scaffolding: 80-90% of the work is done, the remaining polish is intent you carry, not inference we can automate.
A dataclass is a real class with default values, methods, and `__eq__`/`__repr__` auto-generated. A TypedDict is a structural type hint for plain dicts — it's compile-time-only and gives you mypy/pyright autocomplete without changing the underlying `dict` runtime shape.
For in-process data models and domain objects, pick dataclass — it's a real Python class with sensible defaults. For typing a JSON blob you receive from an API and want to keep as a plain dict, pick TypedDict.
Yes. Each unique nested object shape gets its own class, referenced from the parent field's type hint (e.g., `address: Address`). Identical shapes share a name; divergent shapes get numeric suffixes.
If a JSON key is a Python keyword (`class`, `for`, `import`, etc.), the emitted field appends a trailing underscore (`class_`) to stay valid.