Python dict vs JSON: syntax differences explained
The same braces do not make a Python dict valid JSON. Learn which syntax changes matter before you parse or send data.
A Python dictionary and a JSON object both use braces and key-value pairs, so a printed Python value can look like valid JSON. It is not necessarily valid JSON. The differences are small but strict parsers care about every one of them.
For example, this is a Python dictionary:
{'name': 'Ada', 'active': True, 'team': None, 'tags': ('python', 'json')}
The equivalent JSON is:
{"name": "Ada", "active": true, "team": null, "tags": ["python", "json"]}
What changes between Python and JSON?
| Python | JSON | Why it matters |
|---|---|---|
'text' | "text" | JSON requires double-quoted property names and strings. |
True / False | true / false | JSON keywords are lowercase. |
None | null | JSON has one null value. |
(1, 2) | [1, 2] | JSON has arrays, not tuples. |
# comment | Not allowed | Remove comments before parsing JSON. |
Why JSON.parse fails on a Python dict
JSON.parse() accepts JSON syntax only. It will stop at the first single quote, uppercase boolean, None, trailing comma, or comment. That is expected: it is not designed to interpret Python source syntax.
When working inside Python, parse Python literals deliberately with ast.literal_eval() and then serialize them with json.dumps(). Do not use eval() on pasted or untrusted text. Python documents literal_eval() as the safer literal-only option, while the json module documents JSON serialization.
When a conversion is not safe
A dictionary with custom objects, function calls, variables, or arbitrary expressions has no guaranteed JSON equivalent. Convert those values in your program first. JSON supports objects, arrays, strings, numbers, booleans, and null; it does not execute Python code.
A conversion can lose the original type
Consider a copied payload with a coordinate tuple and a set of tags:
{'active': True, 'owner': None, 'coordinates': (40.4, -3.7), 'tags': {'python', 'json'}}
The browser converter writes:
{"active": true, "owner": null, "coordinates": [40.4, -3.7], "tags": ["python", "json"]}
Open this type-conversion example in the editor, then press Convert. The two arrays have the same JSON type even though one came from a tuple and the other from a set. The tag order shown follows this pasted text; a Python set's printed order is not a stable ordering contract. Converting the JSON back produces lists, not the original tuple and set.
If another service depends on those types, agree on a schema before conversion. For example, document coordinates as an ordered pair and tags as unique values. A generic converter cannot reconstruct that meaning from an array.
Why replacing single quotes breaks real text
{"message": "Don't replace every quote", "active": True}
Replacing every single quote would alter the apostrophe in Don't while leaving the uppercase boolean unresolved. A parser distinguishes string content from syntax. Open the apostrophe example and compare the unchanged message with the converted boolean.
Use the Python json documentation for the standard encoder's conversion table. This site's extra representations are described in the converter's limits.