
Options
Paste a Python dictionary or list and it's converted to valid JSON as you type. The converter reads Python's own syntax, so single quotes, True, False, None, tuples, sets, comments, and trailing commas all work. It also understands the output of print() for common objects like datetime, Decimal, UUID, OrderedDict, and defaultdict, which a simple find-and-replace can't handle. Switch to JSON to Python to go the other way. Everything runs in your browser.
How to convert a Python dict to JSON
- Paste the dict, for example output you copied from print(), a log file, or a debugger, into the left pane.
- The JSON appears on the right right away. If something can't be read, the exact line and column are shown with an explanation.
- Check the notes under the panes for anything that was changed, such as sets that became lists or objects that were kept as text.
- Click Copy or Download .json.
How Python values become JSON
| Python | JSON |
|---|---|
'text', "text", '''text''', r'C:\path' | "text", with escapes converted |
True, False, None | true, false, null |
(1, 2) tuple, {1, 2} set | [1, 2] |
{1: 'a'}, {True: 'b'} | {"1": "a"}, {"true": "b"}, matching json.dumps |
0x1F, 1_000, .5 | 31, 1000, 0.5 |
float('nan'), float('inf') | null by default, or text, or NaN like json.dumps |
datetime.datetime(2024, 1, 2, 3, 4, 5) | "2024-01-02T03:04:05" |
Decimal('19.99') | 19.99, keeping every digit |
UUID('...'), PosixPath('/tmp'), ObjectId('...') | The text inside, like "/tmp" |
OrderedDict([('a', 1)]), defaultdict(<class 'list'>, {...}) | A normal object, {"a": 1} |
User(id=1, name='Ann') | {"id": 1, "name": "Ann"}, for dataclass and pydantic reprs |
<object at 0x7f...> | Kept as text, with a note |
Why not just replace the quotes?
Swapping single quotes for double quotes breaks as soon as a string contains an apostrophe, like 'it\'s' or "Bob's", and it doesn't touch True, None, tuples, or escaped characters. Python's own json.dumps() works only on live objects in a running program, not on text you copied from a log. This converter parses the text the way Python does, so every kind of string and value is handled correctly.
Doing it in Python
If you have the text in a Python program, json.dumps(ast.literal_eval(text)) converts plain dicts. It fails on reprs like datetime.datetime(...) or Decimal('1.5'), which this tool handles. To read JSON back into Python, use json.loads(text).
Frequently asked questions
What's the difference between a Python dict and JSON?
They look alike but follow different rules. JSON needs double quotes, uses true, false, and null, and only allows text keys. Python allows single quotes, uses True, False, and None, and has tuples, sets, and keys that are numbers or tuples. JSON is a text format for exchanging data, while a dict is a live Python object.
Why does my converted JSON say "null" where I had nan?
JSON has no NaN or Infinity. Python's json.dumps writes them anyway, which most other JSON parsers reject. By default this tool writes null instead, so the result is valid everywhere. You can change that under NaN and infinity.
Can it convert output from print() or a log file?
Yes. That's what it's built for. Reprs of datetime, date, Decimal, UUID, OrderedDict, defaultdict, Counter, paths, numpy arrays, and dataclasses are all converted, and anything it can't convert is kept as text with a note.
Can I convert JSON to a Python dict?
Yes. Click JSON to Python. true, false, and null become True, False, and None, strings get Python quotes, and you can add a variable name so the result is ready to paste into your code.
What does ensure_ascii do?
It escapes every non-ASCII character, so é becomes \u00e9. Python's json.dumps does this by default. It's off here because modern JSON tools all read UTF-8.
Is my data uploaded anywhere?
No. The conversion happens in your browser and nothing is sent to a server.
