jsonpythonjsondecodeerrordebuggingjavascript

Expecting Property Name Enclosed in Double Quotes: Cause & Fix

·8 min read·Error Fixes

What Does "Expecting Property Name Enclosed in Double Quotes" Mean?

In Python's json module, calling json.loads() on a string with single quotes, unquoted keys, or trailing commas throws:

json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

In JavaScript V8 engines, the equivalent error is:

SyntaxError: Unexpected token ''', "{'name': '..." is not valid JSON

This error means the parser encountered a JSON object literal that violates the strict JSON specification (RFC 8259). In JSON, all keys and string values must be wrapped in double quotes (`"`). Single quotes (') and bare words are strictly invalid.

The 3 Most Common Causes

Cause 1: Single Quotes in Python Dictionaries or JS Objects (Most Common)

In Python, printing a dictionary outputs single quotes by default:

python
data = {'user': 'alex', 'active': True}
print(str(data))  # Output: "{'user': 'alex', 'active': True}"

If you try to parse str(data) back with json.loads(), it crashes immediately because Python printed single quotes, not valid JSON double quotes.

python
import json

# ❌ Crashes with JSONDecodeError
raw = "{'user': 'alex', 'active': True}"
json.loads(raw)

Cause 2: Unquoted Object Keys

JavaScript object literals allow unquoted keys, but JSON does not:

javascript
// ❌ Invalid JSON (bare keys)
{ name: "John", age: 30 }

// ✅ Valid JSON (quoted keys)
{ "name": "John", "age": 30 }

Cause 3: Trailing Commas Before a Closing Bracket

A dangling comma right before a closing brace } makes the parser expect another property name:

json
{
  "name": "Sarah",
  "role": "admin",   <-- trailing comma causes parse failure
}

How to Fix It in Python

Fix 1: Use json.dumps() When Creating Strings

Never convert Python dictionaries to strings using str(dict). Always use json.dumps():

python
import json

data = {'user': 'alex', 'active': True}

# ✅ Serializes with proper double quotes and lowercase booleans
json_str = json.dumps(data)
# Output: '{"user": "alex", "active": true}'

# ✅ Parses cleanly
parsed = json.loads(json_str)

Fix 2: Parsing Single-Quoted Python Dict Strings (ast.literal_eval)

If you received a string with single quotes from an external source or legacy database and cannot change the producer, use Python's built-in ast.literal_eval instead of regex or string replaces:

python
import ast

raw_string = "{'user': 'alex', 'active': True, 'count': 10}"

# ✅ Safely parses Python dictionary literals into a real dict
data = ast.literal_eval(raw_string)

print(data['user'])  # 'alex'
Security Note: ast.literal_eval is safe against arbitrary code execution (unlike eval()), as it only parses literal Python data structures.

How to Fix It in JavaScript / Node.js

Fix 1: Correct JSON.stringify Usage

javascript
const user = { name: 'Alex', active: true };

// ✅ Produces valid JSON with double quotes
const validJSON = JSON.stringify(user);
// '{"name":"Alex","active":true}'

Fix 2: Automated JSON Repair Utility

If you have pasted messy input containing single quotes, unquoted keys, or trailing commas, you can use the JSON Fixer tool or format and test it using the JSON Formatter to clean up syntax automatically.

Summary Checklist

ProblemBroken SyntaxCorrect Syntax
Single quotes{'id': 1}{"id": 1}
Unquoted keys{id: 1}{"id": 1}
Python booleans in raw text{"active": True}{"active": true}
Python None{"data": None}{"data": null}
Trailing comma{"a": 1,}{"a": 1}

Validate any questionable JSON payloads instantly in your browser with JSONKit's JSON Validator.

Try JSON Fixer & Validator

Auto-repair single quotes, unquoted keys, and trailing commas instantly.