Developer / Types

JSON to Python Converter

Turn a JSON sample into Python dataclasses, TypedDict definitions, or Pydantic models, with nested classes, optional and nullable fields, and snake_case names.

JSON to Python Converter: The converter reads the sample's structure: each object becomes a class, arrays become list[...], and objects in an array are merged, so a key missing from some records becomes optional and a key that is sometimes null becomes "| None". Keys that are not valid Python names become snake_case; Pydantic models keep the original key as an alias, and TypedDict switches to its functional form. The output for several tricky samples was run in Python 3.13, with Pydantic validating the sample against it. Runs 100% locally in your browser with zero server file uploads.

Runs
In your browser
Cost
Free · no sign-up
Availability
Ready to use
JSON to PythonLocal processing

Runs entirely in your browser

Python

from __future__ import annotations

from dataclasses import dataclass


@dataclass
class Address:
    city: str
    zip_code: str


@dataclass
class User:
    id: int
    user_name: str
    avatar_url: str
    score: float
    tags: list[str]
    address: Address
    manager_id: int | None
    nickname: str | None = None


UserList = list[User]

Written for Python 3.10 or later. Keys missing from some objects become optional; keys that are sometimes null become “| None”. Dataclasses do not map renamed keys back to JSON, so use Pydantic, which adds aliases, when keys are not valid Python names.

From types to validation

Type hints alone do not check data at runtime: json.loads gives you plain dicts and lists whatever the annotations say. Pydantic models validate and convert the data as it is parsed, with Model.model_validate(data), and report every field that does not fit.

For the same sample in other languages, see JSON to TypeScript and JSON to Go; for a language-neutral contract, JSON to JSON Schema.

Getting a good sample

Paste several records rather than one, including ones with optional or empty fields, so the converter can see which keys are always there. Values that are always null or empty arrays come out as Any, to be filled in by hand.

How to use it

  1. Paste a JSON sample, ideally an array with several typical records.
  2. Choose dataclasses, TypedDict, or Pydantic, and name the top-level type.
  3. Copy the generated classes into your project.

Privacy & limitations

The JSON is converted in your browser and never uploaded.

Related tools

Frequently asked questions

Which style should I use?

Pydantic to validate and parse data from an API, TypedDict to type-check code that passes plain dicts around, and dataclasses for simple internal objects that you build yourself.

Which Python version does the code need?

Python 3.10 or later, for the X | None syntax; NotRequired in TypedDict needs 3.11, or typing_extensions on older versions.

Why are some fields typed Any?

A key that is always null, or an empty array, gives no clue to its type; replace Any with the real type from your API's documentation.

Free tool · runs in your browser · no account required