Python Dict to JSON Converter

Paste the output of a Python print() or repr() and get JSON. There is no mode to select - the same box reads JSON and Python literals alike, and tells you which one it found.

Why a Python dict is not JSON

They look almost identical, which is exactly why this is annoying. The differences are small and every one of them makes JSON.parse fail:

  • Python writes strings with single quotes; JSON requires double quotes.
  • Python writes True, False and None; JSON writes true, false and null.
  • Python allows a trailing comma after the last element; JSON does not.
  • Python has tuples, sets, bytes literals and complex numbers; JSON has none of them.
  • Python allows comments and adjacent string concatenation ('a' 'b'); JSON allows neither.

How this converter works

It parses Python literal syntax properly, the way Python’s own ast.literal_eval does, rather than running find-and-replace over the text. That distinction is not academic. A tool that swaps quote characters with a regex cannot tell a quote that ends a string from an apostrophe inside one, so it quietly corrupts values - a very common failure mode among online converters, and one this tool used to have before it was rewritten.

Where a Python value has no JSON equivalent, the source text is kept rather than the field being dropped. A datetime.datetime(2026, 3, 26) becomes the string "datetime.datetime(2026, 3, 26)", a set becomes an array, a tuple becomes an array, and b’raw’ becomes "raw". Losing a little fidelity is acceptable; losing data silently is not.

Input and output
{'user': 'O\'Brien', 'active': True, 'tags': ('a', 'b'),
 'seen': None, 'raw': b'bytes', 'count': 1_000}

{
  "user": "O'Brien",
  "active": true,
  "tags": ["a", "b"],
  "seen": null,
  "raw": "bytes",
  "count": 1000
}

The other direction

JSON is already valid Python for most documents - json.loads handles it, and a JSON object is a dict once loaded. The only values that need care are true, false and null, which Python spells True, False and None.

Questions

How do I convert a Python dict to JSON online?
Paste the dictionary into the input box. It is converted as you paste - no mode to select and no upload. Press Beautify to rewrite the box as formatted JSON, or explore it as a tree.
Does it handle True, False and None?
Yes, along with single quotes, trailing commas, tuples, sets, frozensets, bytes literals, raw and triple-quoted strings, underscores in numbers, hex and binary literals, comments, and adjacent string concatenation.
What happens to a datetime or a custom object?
Values with no JSON equivalent are kept as their source text rather than dropped - datetime.datetime(2026, 3, 26) becomes that string, so the information is still visible in the output.
Is it safe to paste a dict containing API keys?
Yes. The conversion happens inside your browser and the tool makes no network requests, so the document never leaves your machine.

Open JSON Explorer and try it on your own data