JSON to Python (dataclass)
Convert JSON to a Python dataclass with type hints. Supports List, Optional and nested classes. Everything in your browser.
JSON turned into typed dataclasses
You got a config file or an API payload as JSON and you would rather not sprinkle cfg.get('db').get('host') across the codebase. Typing the equivalent dataclass by hand is repetitive and it is easy to miss a nested field. Paste the JSON here, name the root class, and you get the code with @dataclass, the typing imports and the annotations ready to drop into your module.
Each nested object becomes its own class, named after the key in PascalCase, and it is written above the class that uses it. That ordering matters more than it looks: the file works read top to bottom, with no string annotations and no from __future__ import annotations. In lists only the first element is inspected, and the item class gets an Item suffix, so items becomes ItemsItem. A null value becomes Optional[Any].
The input has to be an object at the top level. An array or a bare value returns the message Esperado objeto, so wrap the list in a key first. Field names are copied verbatim, so keys like user-name or class produce invalid Python: rename them and map on read, or move to Pydantic with Field(alias=...). There is no copy button, select the box and hit Ctrl+C. It all runs in the browser.
Frequently asked questions
Does it output Pydantic models?
What if two keys share a name but have different fields?
Which Python version do I need?
Related Tools
JSON to TypeScript
Convert a JSON to TypeScript interfaces with automatically inferred types. Detects strings, numbers, booleans, arrays, nested objects and union types. Everything in your browser.
CSV → JSON Lines
Convert CSV to JSONL (one JSON object per line). Common format in logs, ML pipelines and document databases.
JSON to C# Class
Convert JSON to a C# class with auto-implemented properties. Detects primitive types, lists, arrays and nested objects. Useful for .NET/Unity. Everything in your browser.
Fixed-Width ↔ CSV/JSON Converter
Converts fixed-width text files to CSV, TSV or JSON and back, with automatic column detection, a position map and per-line warnings.
JSON to Java Class
Convert JSON to a Java POJO class with getters/setters and inferred types. Supports nested classes and arrays as List. Everything in your browser.
JSON to TOML
Convert JSON to TOML, the readable config format used by Cargo (Rust), pyproject.toml, Hugo, etc. Supports strings, numbers, booleans, arrays and nested tables. Everything in your browser.