⚡
usefultools.dev
Py

Python Dict to JSON Converter – and JSON to Python

NOUVEAU

Python dict to JSON converter: turn print() or repr() output with True, None, single quotes and tuples into valid JSON, or JSON into Python. Free, in-browser.

Fonctionne à 100 % dans votre navigateur — vos données ne sont jamais envoyées ni stockées sur nos serveurs.

Cet outil n'est pas encore entièrement traduit : une partie du texte est encore en anglais. L'outil lui-même fonctionne de la même façon dans toutes les langues.

Converted with a note:

  • line 9, column 14: nan has no JSON equivalent, written as null
⚡

Exemples rapides

Des entrées typiques et les résultats produits par cet outil.

Bool
{'a': True}
{"a":true}
None
{'x': None}
{"x":null}
Tuple
(1, 2,)
[1,2]
Int key
{1: 'one'}
{"1":"one"}
JSON to Python
{"ok": true}
{'ok': True}
📖

Présentation

This Python dict to JSON converter takes what Python prints, such as a dict from print(), a log line or a Django shell session, and turns it into strict JSON. True, False and None become true, false and null, single-quoted strings get double quotes, tuples and sets become arrays, trailing commas and # comments are allowed, and hex, octal or underscore numbers are written as plain decimals without losing precision.

It also converts the other way: paste JSON and get a Python literal you can drop into a test, a fixture or a settings file, in repr style with single quotes or Black style with double quotes, on one line or indented.

A real tokenizer and parser read the input; nothing is evaluated, so pasted code cannot run. Values JSON cannot represent, such as nan, inf, bytes or complex numbers, are reported with their line and column. It all runs in your browser.

Pourquoi utiliser cet outil ?

  • Fix "Expecting property name enclosed in double quotes" fast
  • Handles True/None, tuples, sets and comments
  • Never runs your input: parser, not eval
  • Exact big integers, no float rounding
  • Two-way, and fully in your browser
⭐

Fonctionnalités

🐍

Python literal parser

Strings (single, double, triple, raw, adjacent), ints, floats, True/False/None, lists, tuples, dicts and sets.

🔁

Both directions

Python to JSON, and JSON to a Python literal with single or double quotes.

⚠️

Honest warnings

Notes non-string keys, sets, duplicate keys and nan/inf so you know what changed.

♾️

nan and inf policy

Write them as null, as "NaN"/"Infinity" strings, or stop with an error.

📍

Precise errors

Byte strings, f-strings, function calls and syntax errors are reported with line and column.

↹

Indent control

2 spaces, 4 spaces, tabs or a single line in either direction.

🛠️

Mode d'emploi

1

Choose a direction

Select Python → JSON or JSON → Python.

2

Paste the value

Paste the dict, list or JSON into the input box, or press Sample.

3

Pick the options

Set the indent, and the nan/inf handling or the string quotes.

4

Copy the output

Read any notes, then press Copy.

🤔

Questions fréquentes