Three styles
Standard-library dataclasses, Pydantic BaseModel with aliases, or TypedDict for type-checking plain dicts.
Create dataclasses, Pydantic models or TypedDicts from example JSON.
Generate Python dataclasses, Pydantic models or TypedDicts from JSON. Snake_case fields, aliases for camelCase keys, optional fields and nested classes.
{"id":7,"userName":"aarav","tags":["a"],"address":{"city":"Pune"}}from dataclasses import dataclass
@dataclass
class Address:
city: str
@dataclass
class User:
id: int
user_name: str
tags: list[str]
address: AddressTip: Choose Pydantic when you need validation and alias handling; it parses camelCase keys into snake_case fields for you.
Standard-library dataclasses, Pydantic BaseModel with aliases, or TypedDict for type-checking plain dicts.
camelCase keys become snake_case fields; Pydantic keeps the original key as an alias.
Nested objects become their own classes, defined before the classes that use them.
Missing or null values become X | None with a None default, placed after required fields.
Python 3.10 or later, because the output uses list[str] and X | None.
Fields are renamed (class → class_, 2fa → field_2fa). TypedDict switches to the functional syntax so the real keys are kept.
With Pydantic, ISO date strings are typed as datetime or date and parsed automatically. Dataclasses and TypedDict keep str, because json.loads returns strings.
Yes, the code is generated in your browser.