Class name:
JSON Input 0 B
Ready
0 chars
Python Output 0 B
Python dataclasses will appear here...
0 chars
Features

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.

How it works

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.

FAQ

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.