Skip to content
jsonforge.app

JSON to Python

Generate Python TypedDict classes from a JSON sample for mypy, Pyright, and editor autocompletion.

JSON input

Loading editor…

Generated code

Enter JSON on the left to generate a type from it.

What is JSON to Python?

A JSON to Python converter turns a sample JSON document into typed Python class definitions — here, TypedDict classes that describe the exact shape of a dictionary parsed by json.loads. Python will happily hand you back a plain dict from any JSON payload, which is convenient right up until you need to know what is actually inside it: at that point every key access is a guess, typos surface only at runtime, and your editor can offer no completion at all. Declaring the shape as a TypedDict gives mypy, Pyright, and your IDE enough information to autocomplete keys, catch misspellings before the code runs, and flag when a field is used as the wrong type — while the value stays an ordinary dict at runtime, so nothing about how you parse or pass the data has to change.

How to use JSON to Python

  1. Paste a representative JSON payload into the left panel — the generated classes reflect exactly the keys present in that sample.
  2. Set a root class name above the output (defaults to "Root"); every nested object becomes its own class, named for the key that holds it.
  3. Copy the classes into a module and annotate your parsing code, for example `data: Root = json.loads(raw)`.
  4. Use the language picker above the output to generate the same shape as a Go struct, Rust struct, or TypeScript type instead.

Examples

Flat object as a TypedDict

Input

{"id": 1, "name": "Ada", "active": true}

Output

from typing import TypedDict class Root(TypedDict): id: int name: str active: bool

Nested object becomes its own class

Input

{"user": {"id": 1, "name": "Ada", "roles": ["admin"]}}

Output

from typing import TypedDict class User(TypedDict): id: int name: str roles: list[str] class Root(TypedDict): user: User

Common mistakes

  • Assuming a TypedDict rejects bad data at runtime — it does not, so an API that changes shape will still hand you a wrong dict without any error until something downstream breaks.
  • Copying the `list[str]` syntax into a project running Python 3.8 or older, where it raises a TypeError at import time unless `from __future__ import annotations` is present.
  • Generating from a sample where optional keys happen to be absent, producing a class that marks nothing as NotRequired and gives false confidence about what the payload always contains.

Why use this tool

  • Gives editors and mypy/Pyright real key completion and typo detection over data that would otherwise be an opaque dict.
  • Adds no runtime overhead or dependency — the parsed value stays a plain dict, so existing parsing code is unchanged.
  • Runs entirely client-side, so a payload copied from a Django or FastAPI service stays local while these TypedDicts are generated.

Frequently asked questions