Xerobit

JSON to Python Dict Converter

Paste any JSON text to convert it into a valid Python dictionary literal. The tool maps JSON types to their Python equivalents, including true to True, false to False and null to None. It runs entirely in the browser, so nothing is uploaded to a server.

Paste valid JSON here.

Python dict

By · Published · How we build and test tools

How to use the json to python dict converter

  1. Paste your JSON text into the JSON input field.
  2. Set the Indent spaces value (use 0 for a single line).
  3. The Python dict output updates automatically as you type.
  4. Copy the result and paste it directly into your Python script.

How JSON types map to Python

A json to python dict conversion must translate each JSON data type into its Python equivalent. The mapping is straightforward but has a few details worth knowing.

JSON typePython typeExample
objectdict{'key': 'value'}
arraylist[1, 2, 3]
stringstr'hello'
number (integer)int42
number (float)float3.14
trueTrueTrue
falseFalseFalse
nullNoneNone

Notice that JSON uses lowercase true, false and null, while Python capitalises True and False and uses None. A reliable converter handles these substitutions automatically.

String quoting differences

JSON requires double quotes around all string values and object keys. Python accepts both single and double quotes, but the convention (and tools like pprint) favours single quotes. When converting json to python dict literals, double quotes become single quotes.

Escape sequences also differ slightly. Both formats support \n, \t and \\. However, JSON escapes double quotes inside strings as \", while a Python single-quoted string does not need to escape double quotes at all. Conversely, if a JSON string contains a single quote character, it passes through unchanged because JSON does not treat it as special, but it remains safe inside a Python single-quoted string only if there are no unescaped single quotes. This converter leaves single quotes unescaped, matching the behaviour of Python's built-in repr() for simple cases.

Worked example

Consider this JSON input:

{"name": "Alice", "scores": [95, 87], "active": true, "note": null}

The converter parses the JSON, then walks the resulting structure recursively. Strings become single-quoted, the array becomes a Python list, true becomes True and null becomes None. With an indent of 4 spaces the output is:

{
    'name': 'Alice',
    'scores': [95, 87],
    'active': True,
    'note': None
}

This is valid Python syntax and can be assigned directly to a variable.

When to use a literal versus json.loads

Pasting a converted Python dict literal into source code is convenient for configuration, tests and small scripts. For larger or dynamic data, calling json.loads(text) at runtime is safer because it avoids hard-coding values and handles edge cases like very large integers or unusual Unicode escapes.

If you receive data in other formats, you may first need to normalise it to JSON. Tools such as TOML to JSON, INI to JSON or ENV to JSON can help bridge that gap before you perform the final json to python dict conversion.

Common mistakes to avoid

Trailing commas are allowed in Python dicts but forbidden in JSON. If your source text has trailing commas, it will fail JSON parsing before conversion can happen. Remove them first.

Another frequent issue is unescaped control characters. JSON strings cannot contain raw newline or tab characters; they must be written as \n and \t. If you copy text from a log file that contains literal newlines inside a quoted value, the parser will reject it.

Finally, remember that JSON object keys must be strings. Python dicts allow any hashable type as a key, but when converting from JSON every key arrives as a string. If you need integer keys, you must cast them after the conversion.

Worked examples

ExampleInputResult
Simple objectJSON input: {"name":"Alice","age":30}; Indent spaces: 0{'name': 'Alice', 'age': 30}
Nested with booleans and nullJSON input: {"user":{"active":true,"role":null}}; Indent spaces: 2{ / 'user': { / 'active': True, / 'role': None / } / }
Array of objectsJSON input: [{"id":1},{"id":2}]; Indent spaces: 4[ / { / 'id': 1 / }, / { / 'id': 2 / } / ]
Compact outputJSON input: {"a":1,"b":[2,3]}; Indent spaces: 0{'a': 1, 'b': [2, 3]}

FAQ

Does this tool upload my data to a server?

No. The json to python dict conversion happens entirely in your browser using JavaScript. Nothing is sent over the network.

Can I convert a JSON array?

Yes. A JSON array converts to a Python list. If the top-level value is an array rather than an object, the output is a list literal instead of a dict literal.

Why do the quotes change from double to single?

JSON mandates double quotes, but Python convention prefers single quotes for string literals. The converter follows Python conventions so the output looks natural in source code.

What happens to JSON null values?

Every JSON null is converted to the Python keyword None.

Is the output always valid Python?

Yes, provided the input is valid JSON. The converter produces syntactically correct Python literals for all standard JSON types.

How do I go the other direction?

Use the python dict to json tool to convert Python dictionary literals back into JSON format.