Tools
Get Pro

JSON to Python

Paste JSON — get Python dataclasses as you type. Nothing leaves your browser.

to
JSON
Loading the converter…
Python options
› More options & type detection

JSON to Python example

Turn an API response into typed Python classes for your editor and type checker. Each object becomes a @dataclass with type hints, nested objects get their own class, and fields missing from some items get a None default.

JSON input
{
  "user_id": 501,
  "displayName": "Ada",
  "email": "ada@example.com",
  "is_active": true,
  "balance": 12.5,
  "roles": [
    "admin",
    "billing"
  ],
  "profile": {
    "country": "GB",
    "timezone": null
  },
  "last_login": "2026-10-20T09:30:00Z",
  "sessions": [
    {
      "id": "a1",
      "device": "mac"
    },
    {
      "id": "b2"
    }
  ]
}
Generated Python — default settings, type name Account
from dataclasses import dataclass
from typing import Optional, List


@dataclass
class Profile:
    country: str
    timezone: None = None


@dataclass
class Session:
    id: str
    device: Optional[str] = None


@dataclass
class Account:
    user_id: int
    display_name: str
    email: str
    is_active: bool
    balance: float
    roles: List[str]
    profile: Profile
    last_login: str
    sessions: List[Session]
Type hints only, by default
With “Classes only” on you get plain dataclasses. Account(**data) does not turn nested dicts into Profile or Session objects, and fails on renamed keys. Turn “Classes only” off to add from_dict and to_dict functions that convert nested data, check types and read the original key names.
Pythonic names
displayName becomes display_name. Turn off “Transform property names to be Pythonic” to keep the JSON names, so the classes match your keys exactly.
Optional fields and defaults
device is missing from the second session, so it becomes Optional[str] = None, and fields with defaults are placed after required ones, as dataclasses require. timezone is null in every sample, so it is typed None — paste a sample with a value to get a real type.
Python version and Pydantic
The default targets Python 3.7 (Optional, List). Choose 3.9 or 3.10 for built-in list[str] and str | None, or turn on “Uses pydantic BaseModel” to generate Pydantic models instead of dataclasses.

Types that match your real data

Built on the open-source quicktype engine, with quieter defaults and a friendlier editor.

Optional fields detected
Fields that are missing or null in some items become optional automatically.
Merge many samples
Paste JSON Lines or an array — every example contributes to one accurate type.
Paste anything
JavaScript objects, trailing commas, single quotes and comments are repaired for you.
Sensible defaults
No surprise enums or date classes — turn detection on only when you want it.
Every option, every language
All of Python’s generator settings, from naming style to framework annotations.
Private & instant
Runs in a background thread in your browser. Share links keep data in the URL only.

Frequently asked questions

How do I convert JSON to a Python class?+

Paste your JSON and copy the generated classes into a .py file. Set the root class name under Type name. For loading real data, turn off “Classes only” and use the generated from_dict function, for example account_from_dict(json.loads(text)).

Can it generate Pydantic models?+

Yes. Turn on “Uses pydantic BaseModel”. Pydantic builds the nested models from dicts, but snake_case names such as display_name need an alias to read displayName — or turn off Pythonic names.

Why is a field typed None?+

It was null in every sample, so there was nothing to infer its type from. Paste another sample where it has a value.

What if my samples have different fields?+

Paste several samples as JSON Lines (one JSON value per line) or as an array of objects. They are merged into one type, and fields missing from some samples become optional.

Can I paste a JavaScript object from the console?+

Yes. Unquoted keys, single quotes, trailing commas and comments are repaired automatically before the types are generated.

Is my data uploaded?+

No. The conversion runs entirely in your browser, in a background thread. Nothing is sent to a server.

Why don’t I see enums or date types?+

By default, string fields stay strings so the output matches your JSON exactly. Turn on “Detect enums” or “Detect dates” under Options to generate enum and date types.

Code generation uses quicktype (Apache-2.0 license).