Zero Signup ToolsFree browser tools

Converter Tools

Python Dict to JSON Converter

Convert a Python dict to JSON and back in your browser. Handles tuples, sets, True, False, None, hex numbers, single quotes, and trailing commas.

Python Dict to JSON Converter

Direction

Python dict to strict JSON

Indent

Accepts True / False / None, single quotes, triple-quoted strings, hex / octal / binary numbers, underscores in numerics, tuples, sets, frozensets, dict() keyword form, and trailing commas. Output is RFC 8259 JSON.

Up to 400,000 characters. Parsing runs entirely in your browser, so nothing is uploaded.

How Python differs from JSON (Python to JSON)

  • True / False / None become true / false / null.
  • Single quotes and triple quotes become double-quoted JSON strings with proper escapes.
  • Tuples, sets, and frozensets become JSON arrays. The result strip shows how many were converted.
  • bytes literals are decoded as a UTF-8-safe string. Use with care for binary payloads.
  • Hex (0x), octal (0o), and binary (0b) integers are rewritten in decimal. Numeric underscores like 1_000_000 are stripped.
  • float('nan') and float('inf') become null (JSON has no representation for them). The note strip flags each replacement.
  • Non-string keys (int, tuple, bool) are stringified using their Python repr so the JSON parses cleanly. Duplicate keys collapse with later values winning.
  • dict(name="Ada", age=33) keyword form is supported alongside the brace literal.
  • Trailing commas, # line comments, and a leading name = assignment are all accepted.

How JSON renders as Python (JSON to Python)

  • true / false / null become True / False / None.
  • JSON objects become Python dict literals. Keys keep their string form.
  • JSON arrays become Python list literals. Use the Python tuple constructor afterward if you need hashable items.
  • Strings are emitted with your chosen quote style. The other quote kind is left unescaped where possible for readability.
  • Non-ASCII characters can be escaped with \\u and \\U (toggle the ASCII-only checkbox) so the output is safe in any encoding.
  • Integer-valued numbers stay as Python int; other numbers stay as float.

What is intentionally not supported

  • Variable references, function calls, and expressions like 1 + 2. The input must be a self-contained literal, not a Python program.
  • f-string interpolation f"{name}". There is no name to look up, so the f-prefix is read but the braces stay literal.
  • Generator expressions, comprehensions, and lambdas. Materialize them into concrete values first.
  • Decimal('1.0'), datetime(...), and other standard-library constructor calls. Convert to a string or number first.

How to use

  1. Pick the direction: Python to JSON if you have a Python dict you need to use as JSON, or JSON to Python if you have a JSON payload you want as a Python dict literal.
  2. Paste your value into the left panel, or click Load sample to see a clean example or Load messy sample to see tuples, sets, None, NaN, and duplicate keys in action.
  3. Choose an indent (Minify, 2 spaces, or 4 spaces). For JSON to Python, pick single or double quotes and toggle ASCII-only escapes for non-ASCII characters.
  4. Read the converted output on the right and check the strip of notes (tuples converted, NaN replaced with null, non-string keys coerced) to confirm what changed.
  5. Click Copy output to grab the result. The parser runs entirely in your browser, so nothing you paste is uploaded.

About this tool

Python Dict to JSON Converter rewrites Python literal syntax into strict RFC 8259 JSON and runs the reverse direction so you can paste JSON and get an idiomatic Python dict literal back. Python is close to JSON but differs in the spots that make JSON.parse fail every time: True / False / None instead of true / false / null, single quotes and triple quotes for strings, tuples and sets alongside lists, hex (0x), octal (0o), and binary (0b) integer forms, underscores in numerics like 1_000_000, the dict(name='Ada') keyword constructor, trailing commas in any collection, and # line comments. A hand-written tokenizer plus recursive-descent parser reads all of that in one pass, then the emitter writes whichever side you asked for. On the Python-to-JSON side: tuples, sets, and frozensets render as JSON arrays (counted in the result strip), bytes literals decode to ASCII strings, dict keys that are not strings (int, tuple, bool) are coerced to their Python repr so the JSON still parses, duplicate keys collapse with the later value winning (matching dict() semantics), and float('nan') / float('inf') / complex literals become null or a {real, imag} object with a note so nothing silently disappears. Adjacent string literals are concatenated like Python does, raw strings r'...' preserve backslashes, and a leading name = or name: type = assignment is tolerated so you can paste a whole assignment statement. On the JSON-to-Python side: choose 0 / 2 / 4 space indentation, pick single or double quotes for strings, and toggle ASCII-only escapes for safe-across-encoding output. Integer-valued JSON numbers stay as Python int, fractional ones stay as float, true / false / null become True / False / None, and non-ASCII characters render as \u or \U escapes when ASCII-only is on. Everything runs locally in the browser, so the dict you paste in is never uploaded. Useful for porting fixtures between Python tests and a JS or Go service, debugging a Django or Flask response in DevTools, copying a config dict out of a Python script into a JSON file, pulling JSON out of an API trace into a Python repl, generating test data for a Pydantic model, and any time the language you wrote a literal in does not match the language you need to paste it into.

Free to use. Works in your browser. No signup, no login.

Related tools

You may also like

All tools
All toolsConverter Tools