pythonjsonformatter

Paste what you have.

Python dict to JSON converter

Paste a Python dictionary (dict), JSON, or a repr() paste. True, None, tuples, and quotes included. Nothing is uploaded.

  • JSON ↔ Python
  • Tree, viewer, and compare
  • Last 5 stay in this browser

Convert

Processed

Converted history

The last 5 conversions stay in this browser. Open one to put it back in Input.

What is this Python dict to JSON converter?

This Python dict to JSON converter is a free online tool that converts a Python dictionary (dict) to valid JSON and converts JSON back to Python. It handles the three Python literals that RFC 8259 does not allow — True, False, and None — plus single quotes, tuples, trailing commas, and hex numbers. Paste a dict, a repr() output, or a JSON document. The page rewrites it in the other dialect and shows the result in a copy-ready panel, a tree view, a table, the dedicated JSON Viewer, or Diff Checker. Nothing is uploaded: conversion runs in this tab, and the last five results are stored in IndexedDB on this device. Use it when a log line or a REPL paste fails in json.loads. For plain Python literals, a script can use ast.literal_eval followed by json.dumps. This converter also recognizes a limited set of datetime, list, tuple, set, and dict representations without executing Python code. First published January 2026.

This project focuses on copied log and debugger data: a small supported syntax, local processing, and a result you can inspect before using it. Read how the converter works and what it cannot preserve, or check the project updates.

To JSON accepts a Python dict or JSON and writes JSON. Click JSON / dict → Python for pretty Python from JSON or a dict paste. After convert, switch the processed pane to Tree or Table when you want to walk the shape instead of the text. Use JSON Viewer for a larger foldable view with line numbers, or Diff Checker to inspect a second version. See Privacy for how this tool handles your data.

For a plain Python literal that json.dumps() can serialize, use the json module:

import ast
import json

paste = "{'active': True, 'tags': ('python', 'json')}"
obj = ast.literal_eval(paste)
print(json.dumps(obj, indent=4))

This example writes True as true and the tuple as a JSON array. Standard json.dumps() needs an explicit conversion for sets or datetimes, while this browser tool maps supported set and datetime representations to arrays and ISO-8601 strings.

json.dumps argument What it does
indentPretty-print with spaces (this page: 2, 3, 4, or tab)
sort_keysSort object keys; this page keeps paste order
defaultHook for numpy types — convert those in Python first. datetime.datetime(...) becomes ISO-8601 here

.

How do I convert a Python dict to JSON?

  1. Paste a Python dict, a repr(), or JSON in Input. No paste? Use Load sample.
  2. Choose To JSON or JSON / dict → Python.
  3. Press Convert. Copy or download the processed pane.

What we rewrite

Python JSON
True / Falsetrue / false
Nonenull
'text'"text"
(1, 2)[1, 2]
{1, 2}[1, 2]
0x10, 1_00016, 1000
datetime.datetime(2026, 9, 8, 16, 59, 55)"2026-09-08T16:59:55"
Trailing commas, # commentsSet aside

Why True and None break JSON

JSON is not Python. RFC 8259 names only objects, arrays, strings, numbers, true, false, and null. A Python dict printed in a REPL — including the output of repr() — uses True, False, and None, and it often uses single quotes. Tuples and sets are Python types with no JSON equivalent; this page writes them as arrays. Trailing commas and # comments are set aside because they are not in the JSON grammar.

Pasting that repr() into json.loads fails on the first True or None. The standard library is doing the right thing: it is parsing JSON, not Python. For plain literal values that JSON supports, a script can call ast.literal_eval and then json.dumps. Sets need an explicit conversion; ast.literal_eval does not accept datetime.datetime(...). When the text is already on the clipboard, paste it here, choose To JSON, and convert. The other direction writes Python literals again when you need them back in a file. See the json module for the in-process API. That gap shows up when you log a dict, return a debug payload, or copy a REPL line into a JSON parser.

FAQ

How do I convert a paste?

Put text in Input. Choose To JSON or JSON / dict → Python. Press Convert. Use Copy processed or Download processed when the right pane looks right. If Input is empty, Load sample puts a dict with True and None in the box so you can see the rewrite before you paste your own.

What can I paste?

A Python literal (dict, list, tuple, set, True, False, None, comments, trailing commas), the repr() of one of those, or a JSON document. The parser also recognizes supported datetime, list, tuple, set, and dict representations without executing them. Other function calls, f-strings, and arbitrary expressions fail on purpose. Standard ast.literal_eval accepts only literals.

Does my JSON leave this computer?

Your paste does not. Parsing, formatting, tree view, table view, and download all run in this tab. The last five conversions are stored in IndexedDB on this device. Details are on the Privacy page.

Where is converted history?

In the Converted history section above. Each row shows Input and Processed. Open a row to load it back into the editor.

Why did a convert fail?

A red area names the line and column. Click it to jump there. Common causes are a missing comma, an unclosed quote, or an unsupported name. f-strings, arbitrary function calls, and unsupported class instances fail on purpose. Unlike ast.literal_eval, the parser recognizes a small set of safe, named representations such as datetime.datetime(...) without running Python code.

Can I convert a Python repr()?

Yes, when it is a literal. Paste the repr() of a dict, list, tuple, or set. The page maps True, False, and None to JSON and writes double-quoted strings. It will not eval code.

What if my dict has a datetime or numpy int64?

datetime.datetime(...), datetime.date(...), and datetime.time(...) become ISO-8601 strings — the same text isoformat() would write. JSON / dict → Python writes those strings back as datetime.datetime(...) or datetime.date(...). Numpy scalars are still not JSON; convert those in Python first with int(value) or float(value), then paste.

Shortcuts