JSON uses true, false and null
Why True, False and None cause a JSON parse error, and how to get valid JSON out of Python instead of a printed dictionary.
Open the JSON formatterWhat the error looks like
Different engines word this differently. You may see any of these:
Why it happens
- JSON's three literals are lowercase: true, false and null. They are case sensitive.
- Python spells them True, False and None, and printing a dictionary produces Python syntax, not JSON.
- The give-away is that the same document usually has single quotes too, because it is the repr of a dict rather than serialised JSON.
Example
{'active': True, 'deleted': False, 'note': None}
{"active": true, "deleted": false, "note": null}
How this tool reports it
The formatter corrects all three literals and the surrounding single quotes together, so a pasted Python dictionary becomes valid JSON in one pass.
Paste your JSON into the formatter to see the exact line and column, or use the validator if you only need to check it.
Worth knowing
- In Python use json.dumps(value) rather than print(value) or str(value). The latter two produce a repr, which only coincidentally resembles JSON.