Fix JSON.parse “Unexpected token” errors

This error means your input is not valid JSON at a specific character position.

  1. Check for single quotes ('text') — JSON needs double quotes.
  2. Remove trailing commas in objects/arrays.
  3. Make sure you are parsing JSON, not HTML (responses starting with <).
  4. Verify escaped characters inside strings.
// Invalid
{'name':'Kim',}

// Valid
{"name":"Kim"}
Paste suspicious payloads into the JSON formatter to validate and pinpoint structure problems.

JSON.parse error FAQ

What causes JSON.parse unexpected token errors?

They happen when the input is not valid JSON, often because of single quotes, trailing commas, unescaped characters, or a response that is HTML instead of JSON.

How do I fix Unexpected token < in JSON?

Unexpected token < usually means the response starts with HTML. Check the request URL, status code, authentication, and server error page before parsing it as JSON.

Can trailing commas break JSON.parse?

Yes. JSON does not allow trailing commas in arrays or objects, even though JavaScript object literals often do. Remove trailing commas before calling JSON.parse.