JSON to Python TypedDict
Pick TypedDict when the data stays a plain dict and you want type checking with mypy or Pyright.
Loading the tool…
Processing and privacy: The result is calculated inside your browser and your data is not sent to any server.
How to use it
- Enter json input and root type name.
- The result appears straight away and updates as you edit.
- Copy the result, or copy a link that keeps the same values to share it.
How it is calculated
str, int, float, bool, List[T] and Any, with a TypedDict per object. A key missing from some items is wrapped in NotRequired, and null makes the type Optional[T]. If an object has a key that is not a valid Python name, the call form TypedDict("Name", {"key": type}) keeps the keys unchanged.
Example
Inputs: Root type name = Root. Result: Generated code: from typing import List, Optional, TypedDict class Order(TypedDict): order_id: str total: float coupon: Optional[str] class Address(TypedDict): city: str postal_code: str class Root(TypedDict): id: int name: str email: str is_active: bool balance: float tags: List[str] address: Address orders: List[Order]; Types generated: 3; Fields: 13.
{
"id": 1024,
"name": "Sara Ahmed",
"email": "sara@example.com",
"is_active": true,
"balance": 1520.75,
"tags": ["vip", "riyadh"],
"address": { "city": "Riyadh", "postal_code": "12211" },
"orders": [
{ "order_id": "A-1", "total": 99.5, "coupon": "EID10" },
{ "order_id": "A-2", "total": 120, "coupon": null }
]
}from typing import List, Optional, TypedDict
class Order(TypedDict):
order_id: str
total: float
coupon: Optional[str]
class Address(TypedDict):
city: str
postal_code: str
class Root(TypedDict):
id: int
name: str
email: str
is_active: bool
balance: float
tags: List[str]
address: Address
orders: List[Order]Limits and caveats
- NotRequired is in typing since Python 3.11; for older versions import it from typing_extensions.
- TypedDict is for type hints only and does not validate data at runtime.
Questions about this tool
TypedDict or dataclass?
TypedDict describes the plain dict that json.loads returns, while a dataclass is a new object you build from the data.
Why is the call form TypedDict("Root", {}) used sometimes?
A key such as "full-name" cannot be a class attribute name, and the call form accepts any string as a key.
Is my JSON sent to a server?
No. The conversion runs in your browser and the JSON never leaves your device.
