⚡
usefultools.dev
Py

Python Dict to JSON Converter – and JSON to Python

NOVO

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.

Funciona 100% no seu navegador — o que você insere nunca é enviado nem armazenado nos nossos servidores.

Esta ferramenta ainda não está totalmente traduzida, por isso parte do texto continua em inglês. A ferramenta funciona da mesma forma em todos os idiomas.

Converted with a note:

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

Exemplos rápidos

Entradas típicas e os resultados que esta ferramenta gera.

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}
📖

Visão geral

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.

Por que usar esta ferramenta?

  • 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
⭐

Recursos

🐍

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.

🛠️

Como usar

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.

🤔

Perguntas frequentes