Python dict to JSON converter
Fixes the common problem of copying Python print output, which uses single quotes, True and None that JSON rejects.
Loading the tool…
Processing and privacy: The result is calculated inside your browser and your data is not sent to any server.
How to use it
- Enter python dict and indent.
- The result appears straight away and updates as you edit.
- Copy the result, or copy a link that keeps the same values to share it.
How it is calculated
dict becomes an object, list and tuple become arrays, and True, False and None become true, false and null. An integer key becomes a string such as "1" and a True key becomes "true", as json.dumps does. Hex numbers and underscores such as 1_000 become plain decimals.
Example
Inputs: Indent = 2 spaces. Result: JSON: { "name": "Sara", "age": 28, "verified": true, "scores": [ 90, 85.5 ], "manager": null }; Values converted: 6.
data = {
'name': 'Sara',
'age': 28,
'verified': True,
'scores': (90, 85.5),
'manager': None, # not assigned yet
}{
"name": "Sara",
"age": 28,
"verified": true,
"scores": [
90,
85.5
],
"manager": null
}Limits and caveats
- Only literal values are read: variables and calls such as datetime() give an error.
- Sets, bytes, f-strings and complex numbers have no JSON equivalent.
Questions about this tool
Why does json.loads reject print output?
print shows repr with single quotes, True and None, while JSON needs double quotes, true and null. Paste it here to convert it.
What happens to numeric keys?
They become strings because JSON keys are always strings, so the key 1 becomes "1", as with json.dumps.
Can I paste data = { } with comments?
Yes. The tool skips the variable name, the = sign and comments starting with #.
