True, None and NaN in JSON: "Unexpected token" errors
Python True/False/None and JavaScript NaN/undefined are not valid JSON. Exact error messages and the correct values to use.
Error messages you may see
| Chrome · Edge · Node.js | SyntaxError: Unexpected token 'T', ...""active": True, "dat"... is not valid JSON |
|---|---|
| Older Chrome · Node.js 18 and earlier | SyntaxError: Unexpected token T in JSON at position 11 |
| Python json.loads | json.decoder.JSONDecodeError: Expecting value: line 1 column 12 (char 11) |
| This tool | Line 1, Col 12: Expected a value but found 'T' |
Why it happens
JSON only knows true, false and null, all lowercase. Python prints True, False and None, and JavaScript values like NaN and undefined have no JSON equivalent, so the text looks almost like JSON but fails to parse.
Invalid
{"active": True, "data": None, "score": NaN}
How to fix
Use true, false and null. In Python, convert data with json.dumps() instead of printing the dict. Replace NaN with null or a number. The formatter converts these values with Auto-fix.
Fixed
{"active": true, "data": null, "score": null}
Open this example in the JSON formatter →
Tip: the formatter fixes this in one click with the 🔧 Auto-fix button.