Causes and Solutions for JSON "Unexpected token" Errors

JSON Troubleshooting Frontend
Conclusion

Trailing commas, single quotes, and comments—syntax that works in JS will fail in JSON. Put your code through a formatter to instantly identify these issues.

The True Identity of the Error

This error occurs when the string passed to JSON.parse() violates JSON syntax rules.

JSON is completely different from a JavaScript object literal and adheres to much stricter rules.

Common Causes

NG Pattern (Works in JS, FAILS in JSON) Correct JSON
Trailing comma { "name": "Taro", } Remove the final comma { "name": "Taro" }
Missing quotes on key { age: 25 } Enclose in double quotes { "age": 25 }
Single quotes { 'role': 'admin' } Use double quotes { "role": "admin" }
Comments { "data": [] // memo } Comments are disabled { "data": [] }

Debugging Steps

  1. Check the error log — look around at position N for the culprit.

  2. Paste into a formatter — let a tool automatically highlight syntax errors.

  3. Fix and Parse — correct the pointed-out issues, and rerun JSON.parse().

Common Trap

If your output shows [object Object] when using console.log(), it’s already an active object, not a string. There’s no need to pass it into JSON.parse().

Check Syntax with a Tool

By pasting it into a JSON formatter, syntax errors will be highlighted. Because it runs securely within your browser, checking API response payloads is safe.

🧪 Syntax Check with JSON Formatter

Instantly detect errors just by pasting. Data is never sent to any server.

試す