JSON to Python

Generates a Python @dataclass or TypedDict type definition from a JSON sample, or renders the JSON value itself as a Python literal, with null, true, and false correctly translated to None, True, and False.

Private by architecture: All processing is 100% client-side memory. Your data never leaves this browser tab.
JSON input
0 lines · 0 charsJSON
Python output
Ctrl/Cmd+Shift+C
0 charsPython

About This Tool

Turns a JSON sample into a Python type definition, a @dataclass, a TypedDict, or a plain dict/list literal; so a backend or script has a typed shape to work against instead of raw dict access. The swap button runs the conversion in reverse: paste an existing dataclass, TypedDict, Pydantic model, or plain Python dict/list (including OrderedDict, defaultdict, Counter, tuples, or sets), and it comes back as sample JSON.

For Django's models.Model specifically, use JSON to Django Model instead; this tool's dataclass/TypedDict output isn't ORM-aware.

Key Features

  • Three output styles - @dataclass, TypedDict, or a plain Python literal (dict/list), picked from the Style dropdown.
  • Reverse direction: the ⇌ swap button parses existing Python back into sample JSON.
  • Python collection normalizer: the reverse parser also accepts OrderedDict, defaultdict, Counter, tuples, and set/frozenset literals, not just plain dicts.
  • Configurable root name: the Root class name field names the top-level generated class or type.
  • Null-safe typing: a JSON null becomes Optional[Any] rather than a guessed type.
  • File upload & drag-and-drop: load a .json or .py file directly.

Example

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

produces (dataclass mode):

@dataclass
class Root:
	id: int
	name: str
	active: bool
	note: Optional[Any]

FAQ

Can I convert Python code/dicts back to JSON?
Yes! Click the ⇌ swap button or toggle the Direction dropdown to generate mock JSON from Python dictionaries, TypedDict, dataclass, or Pydantic models.
dataclass, TypedDict, or Python literal, which should I use?
@dataclass generates a real runtime class; TypedDict is a type-checking-only shape for plain dicts; Python literal skips types entirely and gives you the actual value as Python source.