JSON Wrench

Python Dict to JSON

Input
All processing happens in your browser. Your JSON is never uploaded.
Output
Paste JSON on the left. It's checked as you type. Broken JSON gets an exact error location and a one-click fix.

When you print() a dict in Python, or copy one from a log or debugger, you get Python syntax: single quotes, True, False and None. It looks like JSON but every JSON parser rejects it.

Paste it above and press Fix. Single quotes become double quotes, True and False become true and false, and None becomes null.

Example

Input
{'name': 'Ada', 'active': True, 'manager': None, 'score': 9.5, 'tags': ['math', 'code']}
Result in JSON Wrench
{
  "name": "Ada",
  "active": true,
  "manager": null,
  "score": 9.5,
  "tags": [
    "math",
    "code"
  ]
}

What gets converted

  • Single-quoted strings and keys become double-quoted, and quotes inside them are escaped correctly.
  • True, False and None become true, false and null.
  • Strings that mix quote styles, such as "it's fine", are kept intact.
  • Text before the dict, such as payload= in a log line, is removed.

What it cannot convert

Some Python values have no JSON equivalent. Tuples like (1, 2), sets, datetime objects and custom class representations such as <User id=7> are not converted. Auto-fix reports that it could not repair the input rather than guessing. Convert those values to lists or strings in Python first.

The better fix in your code

If you control the Python code, print JSON instead of the dict: print(json.dumps(data, indent=2)). For values json cannot serialize, such as dates, pass default=str. Use this page when you only have the printed output, for example from a log, a notebook or a colleague's message.

Frequently asked questions

Is a Python dict valid JSON?

Only sometimes. A dict printed by Python uses single quotes and True/False/None, which JSON does not allow. A dict containing only double-quoted strings, numbers, lists and nested dicts may happen to be valid.

What does None become in JSON?

null. True becomes true and False becomes false.

More JSON tools