What it means, why it happens, and how to fix it.
An "Unexpected token" error means the parser found a character that is not valid at that position in the JSON document. The message often points near the problem, but the real mistake may be just before the reported token.
This usually means there is a trailing comma before a closing brace.
{
"name": "Ava",
}
This usually means the JSON uses single quotes instead of double quotes.
{'name': 'Ava'}
This can happen when a key is unquoted.
{name: "Ava"}
This often means you expected JSON but received HTML, such as an error page, login page, or 404 response.
<html>
<body>Not found</body>
</html>
<, check your API request because the response is probably HTML, not JSON.When a browser or server says "Unexpected token < in JSON", inspect the network response. You may be parsing an HTML error page as JSON. Confirm the status code, content type, authentication, and endpoint URL before changing your JSON parser.
Seeing an unexpected token error? Validate the JSON and jump to the broken line.
Validate JSON