Data Format Conversions

JSON to Python Converter

Convert JSON into Python: a ready-to-paste dict/list literal with True, False and None, or typed models — dataclasses, TypedDicts or Pydantic models inferred from your data, with optional fields detected across array items.
Runs in your browserLive result

Workspace

Options

How to use this tool

  1. 1Paste JSON or open a .json file.
  2. 2Choose a Python literal, dataclasses, TypedDict or Pydantic models.
  3. 3Name the variable or root class.
  4. 4Copy the code or download the .py file.

Frequently asked questions

A dict literal is your data as Python code. Dataclasses, TypedDicts and Pydantic models are type definitions inferred from the data: use them to type-check or validate JSON you load at run time.

All items of an array are merged. A key that is missing from some items becomes Optional[...] = None (dataclass, Pydantic) or NotRequired[...] (TypedDict).

They are not valid Python names, so they become first_name. Pydantic models get Field(alias="first-name") so parsing still works; dataclasses get a comment with the original key; TypedDicts use the functional syntax that keeps the exact key.

The generated code uses list[...] with "from __future__ import annotations", which works on Python 3.7 and later. Pydantic output needs Pydantic v2.