🛠️DevToolKit
🧰Tools
2026-07-08·8 min read

5 Common JSON Errors and How to Fix Them

Troubleshoot JSON parsing errors with clear examples and solutions. Fix trailing commas, encoding issues, and more.

1. Unexpected Token

Error: SyntaxError: Unexpected token < in JSON at position 0 Cause: You're trying to parse HTML or XML as JSON. This usually happens when an API returns an error page instead of JSON. Fix: Check the response content-type before parsing:
if (response.headers.get('content-type')?.includes('application/json')) {
  const data = await response.json();
}

2. Trailing Comma

Error: SyntaxError: Unexpected token } in JSON at position 42 Cause: A comma after the last item in an object or array.
// ❌ Bad
{
  "name": "John",
  "age": 30,
}

// ✅ Fixed
{
"name": "John",
"age": 30
}

Fix: Remove the trailing comma. Our JSON Formatter automatically detects and highlights this error.

3. Single Quotes

Error: SyntaxError: Unexpected token ' in JSON at position 10 Cause: JSON requires double quotes for strings and keys.
// ❌ Bad
{
  'name': 'John',
  'age': 30
}

// ✅ Fixed
{
"name": "John",
"age": 30
}

Fix: Replace all single quotes with double quotes.

4. BOM or Encoding Issues

Error: SyntaxError: Unexpected token \uFEFF in JSON at position 0 Cause: The file has a Byte Order Mark (BOM) character at the beginning. Fix: Save the file as UTF-8 without BOM, or strip the BOM in code:
const json = fs.readFileSync('data.json', 'utf8').replace(/^\uFEFF/, '');
const data = JSON.parse(json);

5. Circular Reference

Error: TypeError: Converting circular structure to JSON Cause: You're trying to stringify an object that references itself.
const obj = { name: "John" };
obj.self = obj; // circular reference

JSON.stringify(obj); // ❌ TypeError

Fix: Remove the circular reference or use a custom replacer:
const seen = new WeakSet();
JSON.stringify(obj, (key, value) => {
  if (typeof value === 'object' && value !== null) {
    if (seen.has(value)) return; // skip circular
    seen.add(value);
  }
  return value;
});

Bonus: How to Debug JSON Errors

  • Use our JSON Formatter — paste your JSON and get instant error highlighting with line numbers
  • Check the error position — the position number tells you exactly where the parser failed
  • Look one character before — the actual error is often just before the reported position
  • Validate in stages — if you have a large JSON, try parsing smaller sections to isolate the issue

Conclusion

Most JSON errors come down to syntax: trailing commas, single quotes, or encoding issues. Use our free JSON Formatter to catch and fix these errors instantly.