Skip to content
100% local

Python dict to JSON

Convert a Python dictionary or list to JSON, and back again.

Input
Output

Python dict to JSON

Paste a Python dictionary or list and this tool converts it to valid JSON — turning True, False and None into true, false and null, and single-quoted strings into double-quoted ones. It also parses Python tuples, since JSON has no tuple type of its own, folding them into JSON arrays. Use it when you copied a variable's value out of a Python REPL, a print() call, or a pprint dump and need the equivalent JSON for an API request, a config file, or a test fixture.

Switch the direction to go the other way, from JSON to Python: object keys and strings render with the quote style you choose (single by default, matching PEP 8, or double), and JSON arrays render as Python lists unless you turn on "Render arrays as tuples". Sort keys alphabetically for a stable diff, or leave the original order in place. Indent with 2 spaces, 4 spaces, a tab, or collapse everything onto one compact line. Turning on "Convert date() / datetime() values" recognizes date(...) and datetime(...) calls in Python input and writes them out as ISO 8601 strings, and does the reverse for JSON strings that already look like an ISO date or timestamp.

The parser accepts both single and double-quoted strings, nested dicts, lists and tuples of any depth, negative numbers, underscores in integers (1_000) and scientific notation. Windows and Unix line endings are treated the same, and the tally under the output reports the key count, line count and character count as you type. If the input isn't valid Python or JSON, the error message points at the exact line and column.

Everything runs locally in your browser — nothing you paste is uploaded anywhere. Copy the result, download it as a .txt file, or send the output straight back into the input to keep converting.

FAQ

What happens to Python tuples?
A tuple like (1, 2, 3) is parsed and converted into a JSON array, since JSON has no separate tuple type. Going from JSON to Python, turn on "Render arrays as tuples" to get tuples back instead of lists.
Does it handle nested dictionaries and lists?
Yes. Dicts, lists and tuples can be nested to any depth, and the converter walks the whole structure in both directions.
What does "Convert date() / datetime() values" do?
When enabled, Python date(2024, 1, 5) and datetime(2024, 1, 5, 9, 30, 0) calls become ISO 8601 strings in the JSON output, and matching ISO strings become date(...) / datetime(...) calls when converting from JSON to Python.
What if my input has a syntax error?
The tool reports the line and column where parsing failed and what it expected there, instead of a generic error, so you can find the problem quickly.
Is my data uploaded anywhere?
No. The conversion runs entirely in your browser — nothing you paste ever leaves your device.