JSON to Python — Generate Pydantic, Dataclass & TypedDict
Paste JSON and get typed Python classes — Pydantic BaseModel, @dataclass, or TypedDict — with nested classes and inferred types (str, int, float, bool, List). Ideal for FastAPI, data validation, and type hints. Everything runs locally in your browser.
This JSON to Python converter turns any JSON sample into typed Python classes. Pick your output style — Pydantic for validation and FastAPI, a plain dataclass, or a TypedDict for lightweight type hints — and the tool infers a Python type for every field, generating nested classes for nested objects. It runs entirely in your browser, so your JSON never leaves your machine.
What this JSON to Python converter produces
- Pydantic
BaseModelclasses (with the required imports) for validation and FastAPI. - Dataclasses (
@dataclass) or TypedDicts when you prefer the standard library. - Nested classes for nested objects, defined before they are used.
- Inferred types:
str,int,float,bool,List[...],Union[...]for mixed arrays, andAnyfor unknown or null values. - Valid Python output for JSON keys containing spaces, hyphens, keywords, or leading digits, while retaining the original key as an alias or TypedDict key.
How to convert JSON to Python
- Paste your JSON into the left editor (or click Load Sample).
- Choose an Output style — Pydantic, dataclass, or TypedDict.
- Click Generate Models, then copy or download the Python classes.
Example: JSON to Pydantic model
Input:
{ "id": 7, "user": { "name": "Ava", "tags": ["x", "y"] }, "score": 9.5 }
Generated Python (Pydantic):
from pydantic import BaseModel
from typing import List
class User(BaseModel):
name: str
tags: List[str]
class Root(BaseModel):
id: int
user: User
score: float
JSON to Python type mapping
- JSON string →
str - JSON integer →
int - JSON number (float) →
float - JSON boolean →
bool - JSON array →
List[...] - JSON object → a nested class
- JSON null / unknown →
Any
FAQs
Can it generate Pydantic models?
Yes. Select the Pydantic output style to get BaseModel classes with the right imports. You can also choose dataclass or TypedDict.
How are nested objects and arrays handled?
Nested objects become their own classes (defined before they are referenced). Homogeneous arrays become List[T]; arrays containing several observed scalar types become List[Union[...]].
Do the field names match my JSON keys?
Valid identifiers are kept by default. Keys that Python cannot use as fields are converted to safe, unique names. Pydantic output adds Field(alias=...), dataclasses record the source key in field metadata, and TypedDict uses functional syntax when it must preserve a non-identifier key exactly.
Is my data uploaded?
No. Everything runs locally in your browser.
Related tools: JSON to TypeScript, JSON to Java POJO, JSON to C#, JSON Validator