D/F DevFormat.tools
Type Generators Runs locally

JSON → Python Dataclass converter

Turn JSON objects into typed Python dataclasses in your browser, including nested models and lists.

Paste your source, then convert it locally.

Private · browser only

Your data stays in this browser. Nothing is uploaded.

Conversion directions

Direction 01

JSON to Python Dataclass

Generate typed Python dataclasses from JSON.

About this converter

Generating Python dataclasses from JSON

Paste a JSON object and the converter emits typed Python dataclasses, including nested classes for nested objects and lists with element types. The output uses the @dataclass decorator and standard typing imports, so it works with both dataclasses and modern type checkers.

Because dataclasses generate __init__, __repr__ and equality for free, you get value objects that are easy to construct, compare and log.

Type annotations and nesting

Strings map to str, numbers to float, booleans to bool, and arrays to list[T]. Nested objects become their own dataclasses referenced by name, which keeps deeply structured payloads organized across multiple classes instead of one flat dictionary.

Loading JSON into dataclasses

After pasting the dataclasses, parse the JSON with json.loads and construct the root class, or use a library like dacite or pydantic to populate nested fields automatically. This turns raw dictionaries into objects with attribute access and type checking.

Frequently asked questions

Which Python version does the output target?

The generated code uses standard dataclasses and built-in generic types available in modern Python 3.

How are invalid Python field names handled?

Field names are sanitized and a metadata mapping preserves the original JSON key.

Does it use the @dataclass decorator?

Yes. Each generated class uses the @dataclass decorator with standard typing imports, so __init__, __repr__ and equality are generated for free.

How are lists typed?

Arrays become list[T] with the element type inferred, matching modern Python typing conventions.

Are nested objects supported?

Yes. Nested objects become their own dataclasses referenced by name, keeping structured payloads organized.

How do I load JSON into the dataclasses?

Parse the JSON with json.loads and construct the root class, or use a library like dacite or pydantic to populate nested fields automatically.