Python

JSON to Python Dict Converter

Writes JSON out as a Python dict literal, with True, False, None and your choice of quotes.

Loading the tool…

Processing happens locally in your browser. What you paste or load is processed by this page and is not uploaded to a server. Nothing is stored unless you use a control that says it stores something, and you can clear anything this site has kept from the privacy page.

How to use this tool

  1. Paste the JSON, or load a .json file with the picker.
  2. Give it a variable name to get an assignment, or clear the field for a bare literal.
  3. Choose the quote style and the indent your project uses.
  4. Select Convert to Python and copy the result straight into your module.

What json to python dict does

Going the other way is the more common errand: an API response or a config file is JSON, and you want it as a literal inside a Python module — a fixture, a default config, a test case. Pasting the JSON directly almost works, and then fails on the first null or true. This page rewrites it properly, so what comes out is valid Python you can paste without editing.

The output is shaped for a file rather than for a screen. Every collection gets a trailing comma, so adding an entry later touches one line in a diff instead of two. Strings use single quotes by default, which is what most Python formatters settle on, and double quotes are an option if that is your house style. Give it a variable name and the result comes back as an assignment, ready to paste; leave the name blank and you get the bare literal. The indent is yours to set, with four spaces as the default because that is the Python convention.

Frequently asked questions

Because Python allows them and a diff is better for it. With a trailing comma, adding an entry to a dict changes one line. Without it, the previous line has to gain a comma too, so the diff shows two changed lines and a reviewer has to check both. Every Python formatter in common use adds them for exactly this reason.

Single by default, because that is what most Python code uses and what the standard formatters produce when there is no reason to prefer otherwise. Switch to double if your project has settled on them — the escaping is handled correctly either way, so a string containing the quote character you chose comes out escaped rather than broken.

Yes — clear the variable name field and the output is the bare literal, ready to paste as a function argument or a default value. If you type something that is not a valid Python identifier, the page will not produce broken code: it falls back to the bare literal and says so in the summary.