Why this conversion needs its own parser
When you print() a Python dictionary, or paste one from a Jupyter notebook, debugger or log line, what you get back is Python's own literal syntax — not JSON. The two look almost identical but differ in exactly the spots that make a strict JSON parser fail: single quotes instead of double, True/False/Noneinstead of true/false/null, and Python-only types like tuples and sets that JSON has no syntax for at all.
This tool runs a small Python-literal parser (not eval(), and nothing is executed) that understands that syntax directly, then re-serialises the result as JSON — so you can take output straight from a Python script and paste it into a config file, an API request body, or a JSON-only tool.
Example
A dict as Python prints it:
{'id': 7, 'active': True, 'ref': None, 'tags': ('a', 'b')}becomes:
{
"id": 7,
"active": true,
"ref": null,
"tags": [
"a",
"b"
]
}What gets converted
- Quotes: single, double and triple-quoted strings, including
r'raw',u'unicode'and adjacent-string concatenation. - Constants:
True→true,False→false,None→null. - Numbers: ints, floats, underscores in literals (
1_000), and hex/octal/binary (0xff,0o17,0b101). - Containers: lists stay arrays; tuples and sets become arrays; nested dicts stay objects.
- Extras: trailing commas and
#comments are ignored, matching how Python itself reads them.
Doing it in Python instead
If you're already inside a Python process, this is the direct equivalent of what the tool does:
import json, ast
data = ast.literal_eval(python_repr_string)
print(json.dumps(data, indent=2))ast.literal_eval is the safe alternative to eval() — it only accepts literal values, never runs code.