EN
My tools

Python Dict to JSON Converter (and JSON to Python)

Convert a printed Python dict, list or tuple to valid JSON — True/False/None, single quotes, tuples, sets, Decimal and datetime — or JSON back to a Python literal.

Convert
JSON

Tuples became JSON arrays.

datetime/date/time values became ISO 8601 text, which is what isoformat() returns.

Decimal values became JSON numbers with exactly their digits (json.dumps would refuse them).

Non-text dict keys became text, as json.dumps does: 1 → "1", True → "true", None → "null".

Big integers keep all their digits; JavaScript rounds integers beyond ±9,007,199,254,740,991 when it reads them.

My tools →
Advertisement

Printing a Python dict gives single quotes, True, False and None, tuples in round brackets — text that looks like JSON but is rejected by every JSON parser. This tool reads Python literal syntax the way Python does (including escapes, raw and byte strings, sets, Decimal, datetime and OrderedDict as they appear in printed output) and writes valid JSON. It also converts JSON back into a Python literal you can paste into code.

How to use this tool

  1. Paste the printed dict, list or tuple — for example from print(), a log or the debugger.
  2. Choose Python → JSON (or the reverse).
  3. Pick the indentation, and how nan and inf should be written.
  4. Copy the JSON.

Formula

True → true · False → false · None → null · 'text' → "text" · (1, 2) and {1, 2} → [1, 2] · {1: 'a'} → {"1": "a"}

Strings follow Python's rules: single, double or triple quotes, r and b prefixes, escapes such as \n, \x41, \u00e9 and \U0001F600, and adjacent literals joined together. Numbers keep their digits, so big integers and Decimal values are exact; hex, octal, binary and underscores are converted. Non-text dict keys become text exactly as json.dumps writes them. datetime, date and time become ISO 8601 text. Nothing is executed: variables, function calls other than the listed constructors and f-strings with expressions are reported as errors.

Example

The sample turns ('admin', 'beta') into ["admin", "beta"], True into true, None into null, the keys 1 and 2 of scores into "1" and "2", datetime.datetime(2024, 2, 29, 13, 45) into "2024-02-29T13:45:00", Decimal('19.99') into 19.99 and keeps all 20 digits of 12345678901234567890.

Frequently asked questions

Why not just replace the quotes?

Replacing ' with " breaks strings such as "It's", leaves True and None, and cannot handle escapes or tuples. Parsing the literal properly gives the same result as json.dumps would.

What happens to nan and inf?

JSON has no such values. They become null by default; you can write them as strings, or as NaN/Infinity the way Python's json module does (most JSON parsers reject that).

Does it run my code?

No. It only reads literal values. A variable name or a call it does not know stops with an error instead of being evaluated.

Is my data uploaded?

No. Everything runs in your browser.

Sources

Last updated:

Cite or embed this tool
APA

kakaoCalc. (2026, November 8). Python Dict to JSON Converter (and JSON to Python). https://kakao.mobile/tools/python-dict-to-json-tool/

MLA

“Python Dict to JSON Converter (and JSON to Python).” kakaoCalc, 8 Nov. 2026, kakao.mobile/tools/python-dict-to-json-tool/.

Paste this code into your page. The widget runs in your visitors' browsers, shows no ads and keeps a link back to this page. Embedding terms

Advertisement