QuietJSON
SyntaxError: Unexpected Identifier

Fix: Unexpected token 'True', 'False', or 'None' in JSON

Pasting raw Python dictionaries, Jupyter notebook printouts, or Django logs into a JSON tool or API endpoint triggers syntax errors because Python and JSON use different literal constants.

SyntaxError: Unexpected token 'T', "{"active": True...}" is not valid JSON

Python vs. JSON Literal Equivalents

Python Literal (Invalid in JSON)JSON Standard (Valid RFC 8259)Meaning
TruetrueBoolean truth
FalsefalseBoolean falsehood
NonenullEmpty / null value

Special Case: Python Literals in Object Key Positions

In Python, dictionary keys can be booleans: {True: "verified"}. However, in JSON, all object keys must be double-quoted strings.

# Python dictionary:
d = { True: "active", None: "unassigned" }

// Valid JSON equivalent (keys must be double-quoted strings):
{ "true": "active", "null": "unassigned" }

How to Fix Automatically

QuietJSON's Repair engine automatically identifies unquoted Python literals and converts them to lowercase JSON primitives in one click without touching strings that contain the words.

Invalid (Python Dict):
{
  "verified": True,
  "pending": False,
  "error": None
}
Valid JSON (RFC 8259):
{
  "verified": true,
  "pending": false,
  "error": null
}

Frequently Asked Questions

Why are True, False, and None invalid in JSON?

JSON (RFC 8259) is derived from JavaScript object syntax, where boolean literals are strictly lowercase 'true' and 'false', and the empty value is strictly 'null'. Capitalized Python constants like True, False, and None are treated as undefined identifier tokens and cause a SyntaxError.

How do I serialize Python dictionaries directly to valid JSON in Python?

Use Python's built-in json library instead of str() or print(): import json; json_string = json.dumps(my_dict). This automatically converts True to true, False to false, and None to null.

What if Python literals are used as object keys?

In Python, dict keys can be booleans like {True: 1}. In JSON, all object keys MUST be double-quoted strings. Therefore, {True: 1} must be converted to {"true": 1} in valid JSON.

Auto-convert Python literals to valid JSON

Use QuietJSON Repair to replace True, False, and None in one click.

Repair JSON Now →