JSON to Python Class

Generate Python dataclasses from JSON

About JSON to Python Class

JSON to Python Class generates a Python @dataclass with one type-annotated field per top-level JSON key — not a populated dictionary or list containing your actual data — entirely in your browser. Strings, numbers, and booleans map to str, float, and bool; arrays are annotated as list and nested objects as dict, since nested values aren't recursively converted into their own dataclasses.

How to use JSON to Python Class

  1. 1Paste your JSON into the input box.
  2. 2Click 'Convert' to generate a Python dataclass from the top-level properties.
  3. 3Review the output — this defines field types, not populated data.
  4. 4Click 'Copy' to copy the code into your project.

Frequently Asked Questions

Is JSON to Python Class free to use?

Yes, it's completely free with no signup required.

Does it generate a Python dict or list with my actual data?

No — it generates a @dataclass type definition with annotated fields like name: str, not populated data. To get your actual JSON as a Python dict, use Python's own json.loads(json_string) instead.

Does it handle nested JSON objects?

No — only top-level keys become typed fields; nested objects are annotated as dict and arrays as list, without generating nested dataclasses.

Is my data uploaded to a server?

No, generation happens entirely in your browser.

Tips & Tricks

  • If you need your actual JSON values as Python data, use json.loads() directly — this tool only generates a type schema, not populated data.
  • For nested objects, manually define additional @dataclass types and update the field annotations to reference them.
  • Numbers always map to float, even for values that look like integers — change to int where that fits your data better.
  • Field names are used exactly as written in your JSON, so non-identifier characters like spaces or hyphens will produce invalid Python — rename them first if needed.