Python Dict to JSON Converter
Turns a Python literal into valid JSON and names every type that had to change on the way.
Loading the tool…
How to use this tool
- Paste the dict, list, tuple or set. Comments and trailing commas are fine.
- Set the indent, or use 0 to get the JSON on one line.
- Select Convert to JSON.
- Read the summary. If it is marked as a warning, it names every type that had to change to fit into JSON.
What python dict to json does
A Python dict printed to a log or copied out of a shell is very nearly JSON, and the small differences are exactly the ones that break a parser: True instead of true, None instead of null, single quotes around strings, a trailing comma, a tuple where JSON expects an array. This page reads the literal the way Python would and writes proper JSON out the other side. Nothing is executed — the text is parsed, not evaluated, so a literal from an untrusted log cannot do anything.
Python has types JSON simply does not have, and the honest thing is to say so rather than convert silently. A tuple and a set both become arrays, and both are reported. A numeric or boolean dictionary key becomes a string, because JSON allows nothing else, and that moves it to the front of the object. nan and infinity become null. Comments are dropped. Whenever any of that happens the result is marked as a warning and the summary lists what changed, so you can decide whether the JSON still means what the Python meant.