JSON to Python

Convert JSON to Python dataclasses online. Nested dataclasses, Optional and List type hints, PEP 8 names.

Generated code will appear here...

Everything runs locally in your browser. Your JSON is never uploaded or stored.

What is a JSON to Python converter?

A JSON to Python converter generates dataclasses with full type hints from a JSON sample. Instead of dicts with unclear shapes, you get typed, self-documenting models for APIs, scripts, and tests — generated locally in your browser.

How to generate dataclasses from JSON

Paste a JSON object or array and the dataclasses appear instantly. Fields with defaults are placed after required fields, as dataclasses require.

Type hints

str, int, float, bool, and List[T] are inferred from the sample. Nested objects become their own dataclasses, and unknown shapes fall back to Any.

Optional fields and usage

Anything that can be missing or null becomes Optional[T] = None. The output only imports from dataclasses and typing — no third-party dependencies — and dataclasses.asdict() converts models back to JSON.

Frequently Asked Questions

How do I convert JSON to Python dataclasses?+
Paste your JSON and every object becomes a @dataclass with typed fields. Nested objects become their own dataclasses and arrays become List[T].
How are field names handled?+
Keys are converted to snake_case for PEP 8 style, e.g. firstName becomes first_name. Reserved Python words get a trailing underscore.
What about missing or null fields?+
Fields that are absent in some array elements or null in the sample are typed Optional[T] with a default of None, matching what the data can actually contain.
Is my data sent anywhere?+
No. Conversion happens entirely in your browser — your JSON never leaves your device.

Related Tools

JSON to Python — free online json to python, json to dataclass, python dataclass from json, json to python class converter, generate dataclass from json, json to python code online, python models from json, convert json to dataclasses, json to typed python, dataclass generator. No signup required. Works in your browser.