JSON•6 min read

Common JSON Syntax Errors and How to Fix Them

Learn the most common JSON mistakes and how to fix them quickly.


JSON is strict. One typo breaks everything. Here are the most common mistakes and how to fix them.


Error: Unexpected Token


**"SyntaxError: Unexpected token ' in JSON at position 0"**


**Cause**: You used single quotes instead of double quotes.


**Wrong**:

{'name': 'Alice'}


**Correct**:

{"name": "Alice"}


JSON spec requires double quotes. No exceptions.


Error: Trailing Comma


**"SyntaxError: Unexpected token , in JSON"**


**Cause**: You left a comma after the last item in an object or array.


**Wrong**:

{

"name": "Alice",

"age": 28,

}


**Correct**:

{

"name": "Alice",

"age": 28

}


Remove the comma after the last property.


Error: Unquoted Keys


**"SyntaxError: Unexpected token n in JSON at position 0"**


**Cause**: Object keys must be quoted.


**Wrong**:

{name: "Alice", age: 28}


**Correct**:

{"name": "Alice", "age": 28}


Always quote keys with double quotes.


Error: Comments in JSON


**"SyntaxError: Unexpected token / in JSON"**


**Cause**: JSON does not support comments.


**Wrong**:

{

// User name

"name": "Alice"

}


**Correct**:

{

"name": "Alice"

}


If you need comments, use a JSON5 parser or store metadata in a separate field.


Error: Undefined Value


**"SyntaxError: Unexpected token u in JSON"**


**Cause**: JSON does not support undefined. Use null instead.


**Wrong**:

{

"name": "Alice",

"middle": undefined

}


**Correct**:

{

"name": "Alice",

"middle": null

}


null is JSON's way to represent an empty value.


Error: Line Breaks in Strings


**"SyntaxError: Unterminated string in JSON"**


**Cause**: Strings cannot contain literal line breaks.


**Wrong**:

{

"bio": "Alice is a

software engineer"

}


**Correct**:

{

"bio": "Alice is a software engineer"

}


Or use \n for line breaks:


{

"bio": "Alice is a\nsoftware engineer"

}


How to Debug JSON


Use the DevToolkit JSON Validator. Paste your JSON and it will show the exact position of the error. The error message often points to the character just after the real mistake, so check one position before.


Quick Checklist


  • [ ] All strings use double quotes
  • [ ] All keys use double quotes
  • [ ] No trailing commas
  • [ ] No comments
  • [ ] Use null for empty values, not undefined
  • [ ] No line breaks inside strings (use \n instead)
  • [ ] No single quotes
  • [ ] Brackets and braces are balanced

One of these five mistakes causes 95% of JSON errors. Check them first.


Practice with DevToolkit

Use the tools to apply what you've learned from this guide.