JSON to Python dataclass

Generate Python dataclasses from a JSON payload, with nested objects lifted into their own classes and snake_case field names.

json
Pythonpy
The result appears here

Questions

Why are nested objects separate classes?+

Python has no anonymous record type, so every object needs a name. Each nested object becomes a class named after the field holding it, declared before the class that uses it.

What are the comments beside some fields?+

The original JSON key, kept where the Python name had to differ. isPro becomes is_pro to read as Python, and the comment is what lets you match it back to the payload when you write the parsing layer.

Why do optional fields come last?+

A dataclass may not place a field with a default before one without, so the generator sorts required fields first. That is a language rule rather than a style choice.

Related tools

The tools are free. So is most of the library.

1935 blocks and 989 pieces for shadcn/ui and Tailwind, built on the same tokens these tools write. Install one with a command and the code is yours.

No signup for the tools. MIT for free blocks, commercial licence for Pro.

Markdown version