Why use this generator
Modern Python
Uses @dataclass decorator (Python 3.7+) and typing module for type hints. Compatible with mypy, Pyright, and IDE autocompletion.
Type mapping
JSON strings become str, integers become int, floats become float, booleans become bool, null becomes None. Arrays become List[T].
Nested classes
Each nested object becomes its own dataclass. Class names are derived from field names, capitalized.
Conversion explained
1. Parse JSON
Input is parsed into a JavaScript value. The class structure is determined by walking the value tree.
2. Collect classes
For each object, a Python dataclass is generated with fields and type hints. The class name is derived from the parent field name, capitalized.
3. Emit Python
Classes are emitted with the @dataclass decorator and proper typing imports. The output is valid Python 3.7+ code.
JSON to Python Dataclass Generator — frequently asked questions
Is this compatible with Pydantic?
Yes — the generated dataclasses use standard Python types that Pydantic can wrap. To use with Pydantic, replace @dataclass with class Model(BaseModel):.
What Python version is required?
Python 3.7+ for @dataclass and the typing syntax used. For older Python, edit the output to use typing.List instead of list.
Are nested classes supported?
Yes — each nested object becomes its own dataclass with a derived name. Lists of objects use the dataclass as the type parameter: List[UserClass].
How are optional fields handled?
Currently all fields are required. For optional fields, edit the output to use Optional[T] = None.
You might also like
JSON to Java
Generate Java POJO classes from JSON
JSON to Go
Generate Go structs from JSON
JSON to C#
Generate C# classes from JSON
JSON to Kotlin
Generate Kotlin data classes from JSON
JSON to TypeScript
Generate TypeScript interfaces from JSON
JSON Validator
Validate JSON syntax with detailed error messages