How to convert JSON to Python
- Paste your JSON into the left panel, or click Load Sample.
- Python is already selected as the output on the right.
- Click Convert, then Copy Output.
Example
This JSON:
{ "id": 101, "name": "Ada Lovelace", "email": "ada@example.com", "active": true, "balance": 250.75,
"address": { "city": "London", "postcode": "N1 9GU" }, "tags": ["admin", "beta"] } becomes:
from __future__ import annotations
from pydantic import BaseModel
class Address(BaseModel):
city: str
postcode: str
class Root(BaseModel):
id: int
name: str
email: str
active: bool
balance: float
address: Address
tags: list[str] How JSON types map to Python
| JSON value | Python type |
|---|---|
"text" | str |
101 | int |
250.75 | float |
true | bool |
{ … } | a new model named after the key |
["a", "b"] | list[str] |
Parsing JSON with the model
root = Root.model_validate_json(raw_json) print(root.address.city) print(root.model_dump_json())
Pydantic checks types while parsing, so a string where a number is expected raises a clear ValidationError. FastAPI uses the same models for request and response bodies.
camelCase keys
Python code uses snake_case. When a JSON key is camelCase, such as userName, the model gets a snake_case field with Field(alias="userName"), so it still reads the original JSON.
Plain classes or dataclasses
Choose Python as the output for simple classes with an __init__ and no dependency. If you prefer the standard library's @dataclass, start from the Pydantic output and swap BaseModel for @dataclass.
Is my JSON sent anywhere?
Pydantic models are generated in your browser. The plain Python option runs on our server: your JSON is converted in memory and not stored. See the privacy policy.
Frequently asked questions
How do I convert JSON to a Python class?
Paste the JSON on the left and click Convert. Python (Pydantic) is selected by default; choose Python for plain classes without type hints.
Which Pydantic version is generated?
Pydantic v2: models extend BaseModel, use built-in generics such as list[str], and parse with model_validate_json.
What happens to camelCase keys?
Fields become snake_case and keep the original key through Field(alias=...).
Is my JSON uploaded?
Pydantic models are generated in your browser. The plain Python option runs on our server and nothing is stored.
Other languages: JSON to Java · JSON to TypeScript · JSON to Go · JSON to C# · JSON to Kotlin · all languages