My Tools Garage

JSON to Python Dataclass

Turn JSON into typed Python @dataclass code.

in-browser

How to use

  1. 1 Paste a representative JSON object into the input box.
  2. 2 Set the root class name (defaults to Root).
  3. 3 Review the generated @dataclass definitions.
  4. 4 Copy the Python code into your project.

About JSON to Python Dataclass

JSON to Python Dataclass converts a sample JSON payload into ready-to-use Python @dataclass definitions, so you can model an API response or config file without typing every field by hand.

Paste your JSON, give the root class a name, and the tool infers a Python type for each key: strings become str, whole numbers int, decimals float, booleans bool, arrays become List[...] with the element type detected from the first item, and null values become Optional[Any].

Nested objects are promoted into their own dataclasses with PascalCase names, and the references are wired up automatically, so a deeply structured payload turns into a clean set of composable classes.

Field names are converted to idiomatic snake_case, keys that start with a digit or use awkward characters are made into valid identifiers, and duplicate class names are de-duplicated with numeric suffixes.

The generated file includes the necessary imports from dataclasses and typing, so it is ready to drop straight into your project.

Everything runs entirely in your browser — your JSON is never uploaded or logged — which makes it safe for internal schemas and private payloads.

Copy the output and start using strongly typed objects in seconds.

FAQ

How are nested objects handled?

Each nested object becomes its own @dataclass with a PascalCase name, and the parent class references it by type.

What types are inferred?

Strings map to str, integers to int, decimals to float, booleans to bool, arrays to List[...], and null to Optional[Any].

Is my JSON sent to a server?

No. The conversion happens locally in your browser, so nothing is uploaded or stored.