Data Format Conversions
JSON to Python Converter
Workspace
Options
How to use this tool
- 1Paste JSON or open a .json file.
- 2Choose a Python literal, dataclasses, TypedDict or Pydantic models.
- 3Name the variable or root class.
- 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.
Related tools
Python Dict to JSON Converter
Convert Python dict, list, tuple and set literals to valid JSON with a safe parser.
JSON to TypeScript Interface Generator
Generate TypeScript interfaces or type aliases from sample JSON, with nested types and optional fields.
JSON Formatter
Beautify JSON with stable indentation and optional key sorting.
Jupyter Notebook to Python Converter
Convert Jupyter notebooks (.ipynb) to Python scripts, with # %% cells, Markdown as comments and magics handled.