JSON to Python
Paste JSON and get typed Python classes β either @dataclass definitions or Pydantic BaseModels. Nested objects become their own classes, and optional fields become Optional[...] with a None default. Everything runs locally in your browser.
Generate Python classes from JSON
Turn a JSON sample into typed Python models in one step β either standard-library @dataclassdefinitions or Pydantic BaseModels. The generator infers each field's type, breaks nested objects into their own classes, wraps arrays in List[...], and marks fields that are not always present as Optional[...] with a None default. The result is ready to paste into a module and use for parsing or validating the same payloads.
How to use it
- Paste a JSON object (or an array of objects for better optionality detection) into the input.
- Choose dataclass or Pydantic with the Style selector and set the Root name.
- Copy the generated classes on the right into your project.
A worked example
This JSON:
{ "id": 10, "name": "Ada Lovelace", "active": true }produces (dataclass style):
from dataclasses import dataclass
@dataclass
class Root:
id: int
name: str
active: boolSwitch the style to Pydantic and the same fields appear on a BaseModel subclass, giving you automatic validation when you construct the object from untrusted input.
When you would reach for it
Modelling an API response in a FastAPI or Flask service, defining request/response schemas, or building typed fixtures for tests. For other targets, see JSON to TypeScript and JSON to Go; to validate payloads language-agnostically, generate a JSON Schema.
Privacy
Generation runs entirely in your browser and works offline once loaded. Your JSON is never uploaded or stored, so pasting a real response with sensitive values is safe.
Frequently asked questions
Dataclass or Pydantic β which should I pick?
Use @dataclass for plain, dependency-free models that just hold data. Choose Pydantic when you want runtime validation and parsing β it checks types and coerces input, which is why frameworks like FastAPI build on it.
How are optional fields handled?
Fields that are missing or null in some records become Optional[...] and are ordered after required fields with a None default, so the generated class is always syntactically valid (required args cannot follow defaulted ones in Python).
How are nested objects handled?
Each nested object becomes its own class, defined before the class that references it, so the output runs top-to-bottom without forward-reference errors.
What types are inferred?
Strings, int, float, bool and None map directly. Arrays become List[...], nested objects become a class type, and mixed element types fall back to Any.
Do I need to install anything?
The dataclass output needs only the standard library (dataclasses and typing). The Pydantic output requires pip install pydantic.
Does my JSON get uploaded?
No. Classes are generated entirely in your browser β nothing is sent to a server.