JSON to Python Dict
Convert JSON to a Python dictionary literal — maps types to None, True/False, and native dict/list.
or drop a file here
Python dict
data = {
'name': 'Alice',
'age': 30,
'active': True,
'score': 98.5,
'tags': [
'python',
'developer',
],
'address': {
'city': 'London',
'zip': None,
},
}How JSON to Python dict conversion works
JSON values are mapped to their Python equivalents: null → None, true/false → True/False, arrays → lists, objects → dicts, numbers stay as numbers, and strings use single-quote notation. Nested structures are indented with 4-space Python style.
For type-annotated Python models, consider using a library like Pydantic. For TypeScript interfaces from JSON, try JSON to TypeScript. For other languages, see JSON to Kotlin or JSON to Swift.
Built and maintained by Meet Shah · Last updated
What this tool is used for
- Pasting an API response into a Python script as a literal for a quick experiment.
- Producing a fixture dictionary for a test without loading a file.
- Converting a payload into Python syntax for a notebook cell.
- Turning a config sample into a literal for a default value.
- Checking how JSON's null and booleans map onto Python's.
Frequently Asked Questions
- What actually differs between JSON and a Python dict literal?
- Three keywords and the quotes. `null` becomes `None`, `true` becomes `True`, `false` becomes `False` — capitalised, because Python's are proper singletons rather than lowercase literals — and the output uses single quotes, which is what `repr` and most style guides produce.
- Do I need this if `json.loads` exists?
- Not for parsing data at runtime — use `json.loads`, always. This is for the other case: pasting a literal into source code, a test fixture or a notebook cell, where you want a real dict in the file rather than a string that has to be parsed on every run.
- How are strings escaped?
- Backslashes doubled, single quotes escaped, newlines and carriage returns written as `\n` and `\r`. Escaping the quote character is the one that matters — an apostrophe inside a single-quoted Python string is a syntax error, and it is exactly the character real-world text contains.
- What happens to duplicate JSON keys?
- The last one wins, silently, because JSON.parse builds an object before the conversion ever sees it. JSON permits duplicate keys and Python dicts cannot hold them — a genuine information loss no converter can avoid, so it is worth knowing your input has none.
- Is a JSON number always safe as a Python number?
- Not exactly. Python has unlimited-precision integers while parsing here goes through a double, so an integer beyond 2⁵³ arrives already rounded. If the payload carries large IDs, keep them as strings before they reach any JavaScript parser.
Common errors and gotchas
- Forgetting that JSON `null`, `true` and `false` become `None`, `True` and `False`, which are not interchangeable.
- Pasting JSON directly and relying on it being valid Python, which it is not once nulls or booleans appear.
- Losing key ordering assumptions, though modern Python dictionaries do preserve insertion order.
- Producing a literal so large it becomes unreadable, where loading from a file would be better.
- Assuming a JSON number maps to int, when a decimal point makes it a float with different behaviour.
Related Converters tools
JSON to YAML
Convert JSON into clean, readable YAML instantly.
YAML to JSON
Convert YAML configuration into valid JSON.
JSON to XML
Convert JSON structures into nested XML markup.
HWB to HEX Converter
Convert an HWB color to HEX.
JSON to SQL
Turn a JSON array of objects into SQL INSERT statements.
CSV to XML
Convert CSV rows into structured XML records.
XML to CSV
Flatten repeated XML records into CSV rows.
INI to JSON
Parse INI config sections and keys into JSON.