Skip to content
gohacks.dev
Tooling

Python Dict to JSON Converter

Convert a Python dict, list or repr() output to valid JSON: single quotes, True, False, None, tuples and triple-quoted strings are translated.

Free · No sign-up · Your inputs stay in your browser

Input

Convert a Python dict to JSON

Output

JSON

156 characters

Reads the repr Python prints: single quotes, True, False and None, tuples (which become arrays), triple-quoted strings and underscores in numbers. Objects such as datetime(...) or Decimal('1.5') have no literal form; convert them with json.dumps(obj, default=str) at the source.

Runs in this browser. Nothing you paste is sent to a server.

Why print() output is not JSON

Printing a dict shows its repr, which uses single quotes and Python's own constants, so pasting it into a JSON tool fails on the first character. The right fix in code is json.dumps(data) rather than str(data); this converter is for the logs and notebooks where only the repr survived. Python's own ast.literal_eval() reads the same syntax safely.

Values with no literal form

Objects such as datetime(...), Decimal('1.5') or a class instance print as constructor calls, which are not literals and cannot be converted. Serialise them at the source with json.dumps(obj, default=str).

Share

Frequently asked questions

Why not just replace single quotes with double quotes?
Because strings contain apostrophes, True and None need translating, and tuples need brackets. A real parser handles all of it without corrupting text such as it's.
What happens to tuples and sets?
Tuples become JSON arrays. Sets print with braces and no colons, which is not a literal JSON can represent, so convert them to lists first.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Keep planning

Similar tools