Common JSON Errors & How to Fix Them
JSON is strict by design. A single misplaced comma or missing quote can break your entire document. Here are the most common JSON errors and how to fix them.
1. Trailing Commas
Unlike JavaScript, JSON does not allow trailing commas after the last item in an object or array.
// ❌ Invalid — trailing comma
{ "name": "John", "age": 30, }
// ✅ Valid
{ "name": "John", "age": 30 }2. Unquoted Keys
All object keys in JSON must be wrapped in double quotes. Single quotes or bare identifiers are not valid.
// ❌ Invalid — unquoted key
{ name: "John" }
// ❌ Invalid — single quotes
{ 'name': 'John' }
// ✅ Valid
{ "name": "John" }3. Missing Brackets or Braces
Every object must have a matching closing brace } and every array a matching closing bracket ].
// ❌ Invalid — missing closing brace
{ "items": [1, 2, 3 ]
// ✅ Valid
{ "items": [1, 2, 3] }4. Single Quotes Instead of Double Quotes
JSON requires double quotes for strings. Single quotes are only valid in JavaScript object literals, not in JSON.
// ❌ Invalid — single quotes
{ "message": 'Hello world' }
// ✅ Valid
{ "message": "Hello world" }5. Invalid Number Formats
JSON does not allow leading zeros, hexadecimal literals, or special number values like Infinity or NaN.
// ❌ Invalid
{ "value": 01, "hex": 0xFF, "inf": Infinity }
// ✅ Valid
{ "value": 1, "hex": 255, "inf": null }6. Unescaped Special Characters
Control characters and certain special characters must be escaped in JSON strings using backslash sequences.
// ❌ Invalid — unescaped newline
{ "text": "Hello
World" }
// ✅ Valid
{ "text": "Hello\nWorld" }How to Debug JSON Errors
• Use a JSON validator or formatter to identify syntax issues quickly
• Check for trailing commas after the last element in objects and arrays
• Verify all keys and string values use double quotes, not single quotes
• Count your brackets and braces to ensure they all match
• Look out for invisible unicode characters that can break parsing
Validate and format your JSON with our JSON Formatter or compare two JSON documents with the JSON Compare tool.