Convert JSON into a Python dict literal — true/false/null become True/False/None, strings are escaped for Python, and the result is valid Python 3 as-is.
Show calculation steps
Processed privately in your browser — nothing you paste is uploaded, logged or stored.
Three keywords from crashing
JSON is nearly valid Python — nearly. Paste a document with true, false or null into a .py file and it crashes at import. This converter rewrites exactly those (True/False/None), applies Pythonic quoting and indentation, and outputs a dict literal that is valid Python 3 as-is — the structure json.loads() would produce, without the runtime parse.
Worked example
{ "experiment": "ab-test-42", "enabled": true, "fallback": null }becomes:
data = {
"experiment": "ab-test-42",
"enabled": True,
"fallback": None,
}When to use it
- pytest fixtures and mock responses from captured payloads.
- Default configuration dicts and lookup tables in source.
- Teaching materials where a runnable literal beats a JSON string.
Limitations to know
- For runtime data, json.loads remains correct — literals are for static data you want readable in source.
- Unicode passes through natively (Python 3 strings are unicode); no \u escapes clutter the output.
Common errors and fixes
- Formatter fights — output uses double quotes matching Black; switch the option if your codebase standardizes on single quotes.
- Trailing commas — idiomatic Python; they make future diffs one line.
How to use the JSON to Python Dictionary Converter
- Paste JSON into the input panel.
- Pick the quote style and declaration prefix.
- Click "Convert to Python".
- Paste the dict into your Python source — it is valid Python 3 as-is.
Frequently asked questions
What is the difference between JSON and a Python dict literal?
Three keywords: true/false/null become True/False/None. Plus Pythonic quoting and indentation. Everything else in JSON is already valid Python syntax — but those three keywords make raw JSON crash, which is what this converter fixes.
Why not just call json.loads() in my code?
For runtime data you should. The literal is for static data — test fixtures, default configs, lookup tables — where a readable in-source dict beats parsing a string at import time.
How is unicode handled?
Python 3 strings are unicode natively, so é, हिन्दी and emoji pass through as-is — no \u escaping needed, and the output stays readable.
Single or double quotes?
Double quotes match Black (the dominant Python formatter); single quotes are a common house style. Both are semantically identical — pick your codebase's convention.