Troubleshooting ยท 7 min read

JSON syntax errors are among the most frustrating bugs in web development. They often appear as cryptic messages like "Unexpected token" or "Expected property name." This guide covers the ten most common errors and exactly how to fix them.

1. Trailing Commas

Error: Unexpected token ] or }

Wrong: {"name": "John", "age": 30,}

Fix: Remove the comma after the last item: {"name": "John", "age": 30}

2. Unquoted Keys

Error: Expected property name

Wrong: {name: "John"}

Fix: Wrap keys in double quotes: {"name": "John"}

3. Single Quotes Instead of Double

Wrong: {'name': 'John'}

Fix: Use double quotes: {"name": "John"}

4. Unterminated Strings

Error: Unterminated string

Cause: Missing closing quote, or unescaped quote inside a string.

Fix: Ensure every string starts and ends with ". Escape internal quotes: "He said \"hello\""

5. Missing Commas Between Items

Wrong: {"a": 1 "b": 2}

Fix: Add commas: {"a": 1, "b": 2}

6. Comments in JSON

Standard JSON does not support comments. Remove // and /* */ comments before validation.

7. Undefined Values

Wrong: {"value": undefined}

Fix: Use null instead: {"value": null}

8. Mismatched Brackets

Wrong: {"items": [1, 2, 3}

Fix: Match opening and closing: {"items": [1, 2, 3]}

9. Invalid Escape Sequences

Use valid escapes: \" \\ \n \t \u0041. Invalid escapes like \x will fail.

10. Numbers with Leading Zeros

Wrong: {"zip": 01234}

Fix: Store as string: {"zip": "01234"}

Quick Fix with AI

Our JSON viewer highlights errors with exact line numbers. Click AI Fix to automatically correct most of these issues. For manual debugging, see How to Validate JSON.