Python boolean and null
- Input
- {'ativo': True, 'chefe': None}
- Expected output
- {"ativo":true,"chefe":null}
Four changes: two quotes and two values.
python dict to json
Paste the dictionary the way Python printed it and turn repair on. The output is strict JSON, and the list of changes shows every quote and value swapped, with the exact column, so you can check before applying.
Four changes: two quotes and two values.
Five single-quoted strings become double-quoted.
JSON has no NaN, so it becomes null.
Curly quotes become straight.
Becomes a string so the zeros are not lost.
The most common causes are a comma after the last item, single quotes, an unquoted key, a comment, and a missing comma between two values. JSON.parse reports only the first problem and, in some browsers, only a character position. This formatter lists every error in the text, each with line and column, shows the snippet with an arrow under the exact spot, marks the line in the editor margin, and has a Go to the error button that selects the spot.
Use json.dumps(data) from the standard library json module. With indent=2 it comes out formatted, with ensure_ascii=False accents stay readable, and with allow_nan=False the code fails if it meets NaN or Infinity instead of producing invalid JSON.
The repr of a string picks single quotes by default, and only uses double quotes when the text already contains a single quote. It is a Python convention for displaying objects, unrelated to the JSON format.
No. Those types do not exist in JSON and their repr is not a syntax that repair can read safely. The error list shows where they are, and you swap them for an ISO 8601 string, a number or a list.
No. Keys come out in the original order unless you choose Sort keys. Python dictionaries keep insertion order since version 3.7, and that order is preserved.