What is JSON → Python Dataclass?
Generate Python code from JSON data. Choose between dataclasses, pydantic models, or plain classes.
Nested objects become their own classes with typed fields and from_dict / to_dict helpers. Output updates as you type, and everything runs in your browser.
Features
- Generate dataclasses, pydantic models, or plain classes
- Type hint generation for Python 3.6+
- Handles nested structures and lists
- Optional field support with defaults
- Copy generated code to clipboard
- Client-side processing for privacy
How to use JSON → Python Dataclass
- Paste your JSON. Enter a sample JSON object.
- Select format. Choose dataclasses, pydantic models, or plain classes.
- Copy Python code. Get ready-to-use Python code with proper typing.
Examples
Generating Python classes
A small user record with a nested address, generated with the default settings. Trimmed to the first 30 lines of the generated classes. The default output also includes from_dict/to_dict helpers and converter functions.
Input
{
"id": 1,
"name": "Ada Lovelace",
"email": "ada@example.com",
"active": true,
"tags": ["admin", "dev"],
"address": { "city": "London", "zip": "EC1A" }
}Output
@dataclass
class Address:
city: str
zip: str
@staticmethod
def from_dict(obj: Any) -> 'Address':
assert isinstance(obj, dict)
city = from_str(obj.get("city"))
zip = from_str(obj.get("zip"))
return Address(city, zip)
def to_dict(self) -> dict:
result: dict = {}
result["city"] = from_str(self.city)
result["zip"] = from_str(self.zip)
return result
@dataclass
class Root:
id: int
name: str
email: str
active: bool
tags: List[str]
address: Address
@staticmethod
def from_dict(obj: Any) -> 'Root':Frequently asked questions
What output formats are available?
Python dataclasses, pydantic BaseModel classes, or plain classes with or without type hints.
Can I use this with Flask or Django?
Yes. Generated code works with Flask, Django, FastAPI, or any Python project.
