Error 1: Single Quotes Instead of Double Quotes
Standard JSON forbids single quotes (`'`). All object keys and string values MUST be enclosed in double quotes (`"`).
// ❌ INVALID (Single Quotes)
{ 'name': 'Alice', 'role': 'developer' }
// ✅ VALID (Double Quotes)
{ "name": "Alice", "role": "developer" }Explanation: Always use double quotes around keys and strings in JSON.
Error 2: Trailing Commas in Objects or Arrays
Unlike JavaScript ES2017, trailing commas after the last array item or object property are strictly invalid in JSON specifications.
// ❌ INVALID (Trailing Comma)
{
"items": [1, 2, 3,],
"status": "ok",
}
// ✅ VALID (No Trailing Comma)
{
"items": [1, 2, 3],
"status": "ok"
}Explanation: Remove all trailing commas before closing brackets or braces.
Error 3: Unquoted Object Keys
In JavaScript object literals, key quotes can often be omitted (`{ name: "Alice" }`). In JSON, every object key must be wrapped in double quotes.
// ❌ INVALID (Unquoted Keys)
{ name: "Alice", age: 30 }
// ✅ VALID (Quoted Keys)
{ "name": "Alice", "age": 30 }Explanation: Quote all key names with double quotes.
Error 4: Comments inside JSON Files
Standard JSON does not support single-line (`//`) or multi-line (`/* */`) comments. Including comments causes `Unexpected token /` errors during parsing.
// ❌ INVALID (Comments Present)
{
// User ID
"id": 101
}
// ✅ VALID (Comments Stripped)
{
"id": 101
}Explanation: Strip all comments before parsing JSON data in standard engines.