JSON Tools

JSON to Python

Convert JSON into a Python dict/list literal, with true/false/null correctly mapped to True/False/None.

Use the tool ↓

Your data is processed locally in your browser and is not uploaded to our servers.

JSON input
JSON
Python
Paste JSON to convert.

About this tool

JSON and Python's built-in data structures line up closely — a JSON object maps naturally onto a Python dict, and a JSON array onto a list — which is exactly why Python's standard library json module can parse JSON directly into native Python objects with no configuration. Where the two genuinely diverge is in a small set of literal spellings: JSON's true, false, and null are lowercase keywords, while Python's equivalents — True, False, and None — are capitalized. Paste JSON directly into a Python file expecting it to work as a literal, and it'll fail with a syntax error on the very first boolean or null it hits.

This converter handles exactly that translation: every true becomes True, every false becomes False, every null becomes None, with everything else — strings, numbers, nested objects and arrays — carried across structurally unchanged, just reformatted with Python's indentation conventions. The result is a literal you can paste directly into a .py file and assign to a variable, and it'll behave exactly like the equivalent JSON parsed through json.loads() — because structurally, it is the same data.

This is a text-level conversion, not code execution — your JSON is parsed as data and re-serialized as Python syntax; nothing you paste is ever run. That distinction matters because the whole point of a tool like this is to give you a trustworthy starting point (test fixtures, mock data, hardcoded config) without introducing any risk from executing arbitrary input.

Strings are output with single quotes, matching common Python style conventions (though double quotes are equally valid Python and PEP 8 doesn't mandate either), and any single quote inside a string value is automatically escaped so the generated code stays syntactically correct. Everything runs locally in your browser; nothing you paste is uploaded anywhere.

How to use it

01

Paste your JSON

Any valid JSON object or array works.

02

Set a variable name

Choose the name the generated data will be assigned to.

03

Copy or download

Paste directly into a .py file, or download it ready to use.

Example

JSON
{"name":"John","age":30,"active":true,"notes":null}
Python
data = {
    'name': 'John',
    'age': 30,
    'active': True,
    'notes': None
}

Common use cases

Creating test fixtures

Turn a JSON example into a Python dict for pytest fixtures.

Hardcoding sample data

Paste an API response into a script as static mock data.

Building config dictionaries

Convert a JSON config into a Python config module.

Data science quick starts

Get JSON sample data into a notebook as a native Python structure.

Debugging API responses

Paste a response into a REPL as real Python data to inspect interactively.

Teaching Python data structures

Show how JSON maps onto Python's dict and list literals.

Frequently asked questions

Related tools

Related articles