Dad’s Data formats tools

JSON → Python

Generate Python TypedDicts from JSON — nested classes, Optional fields, and List types. 100% local.

JSON Input
Root class name
Python Output
Paste JSON to generate Python TypedDicts.

How TypedDict Inference Works

The inferrer walks your JSON and produces Python 3.8+ TypedDict classes. Each JSON object becomes a typed class with field annotations. Nested objects are emitted as separate named TypedDict classes. Null values produce Optional[T] annotations. The output includes the required from __future__ import annotations header to enable forward references, so class definitions can reference each other regardless of order.

Input
{
  "user": {
    "id": 1,
    "name": "Alice",
    "email": "[email protected]",
    "score": 9.5,
    "tags": ["python", "typing"],
    "address": {
      "city": "Amsterdam",
      "country": "NL"
    },
    "deleted_at": null
  },
  "total": 42,
  "active": true
}
Output
from __future__ import annotations
from typing import Any, List, Optional, TypedDict

class Address(TypedDict):
    city: str
    country: str

class User(TypedDict):
    id: int
    name: str
    email: str
    score: float
    tags: List[str]
    address: Address
    deleted_at: Optional[Any]

class Root(TypedDict):
    user: User
    total: int
    active: bool

Type Mapping

JSON valuePython typeNotes
"string"strAny string value
42 (integer)intNumber with no decimal point
3.14 (decimal)floatNumber with a decimal point
true / falseboolBoolean literal
nullOptional[Any]Null-only fields become Optional[Any] — refine manually
["a", "b"]List[str]Homogeneous array infers element type
[1, "a"]List[Any]Mixed-type arrays fall back to Any
{} or { ... }Named TypedDict classNested objects become separate classes
[] (empty)List[Any]Empty array — element type cannot be inferred
Tip: Fields missing from some objects in a heterogeneous array are emitted as Optional[T]. The from __future__ import annotations import enables forward-referencing class names, which is required when classes reference each other.

Limitations to Know

Warning: TypedDict provides only static type checking — Python does not validate TypedDict fields at runtime. If you need runtime validation, consider pairing the generated types with pydantic models or using isinstance checks. Also, null-only fields generate Optional[Any] — update them toOptional[str], Optional[int], etc. once you know the real type.

Try It

Interactive — edit the input to see the output update
Try it
Result

Frequently Asked Questions

Your files stay on your computer. Dad promised.

Data formats tools

Search the Data formats tools