If you write Python, you've probably done this: you print a dict to the console, copy it, and paste it into a JSON formatter — only to get a wall of red. A Python dict looks a lot like JSON, but it isn't JSON. Here's what's different and how to convert it without cleaning up the syntax by hand.
Python dict vs. JSON
Take this dictionary:
{
'name': 'John Doe',
'age': 30,
'is_active': True,
'nickname': None,
'skills': ('python', 'json', 'convert'),
'address': {
'city': 'New York',
'zip': '10001',
},
}Readable, but not valid JSON. Four things in there break a strict JSON parser:
- Single quotes. JSON only allows double quotes. Python happily uses
'single quotes'for keys and strings. - None, True, False. Python capitalizes them; JSON wants
null,true,false. - Tuples.
(1, 2, 3)has no JSON equivalent and is usually a syntax error. - Trailing commas. Legal in Python, but the last item followed by a comma is invalid in strict JSON.
The usual workaround is tedious
The typical path is to run json.dumps(d) in a script, or paste into a tool and fix each error one at a time: replace quotes, change None to null, convert tuples to lists. It's boring and error-prone, especially for nested data.
The faster option: paste the dict into a converter that already understands Python syntax. It normalizes single quotes, None/ True/ False, tuples, and trailing commas into clean, standards-compliant JSON — all in your browser, nothing uploaded to a server.
Try it
Paste any Python dict into the Python dict to JSON converter and it produces valid JSON on the spot, with a tree view for checking the result. No setup, no script, no manual cleanup.