Unexpected token in JSON

Why 'Unexpected token in JSON at position 0' happens and how to fix it. Usually the text is not JSON at all: an HTML error page, an empty response, or a stray character.

Open the JSON formatter

What the error looks like

Different engines word this differently. You may see any of these:

Why it happens

Example

Invalid
<!DOCTYPE html>
<html>
  <body>404 Not Found</body>
</html>
Valid
{
  "error": "Not Found",
  "status": 404
}

How this tool reports it

The formatter names the character it found and the line and column it found it on, rather than a byte offset, so you can see immediately whether you are looking at JSON or at something else entirely.

Paste your JSON into the formatter to see the exact line and column, or use the validator if you only need to check it.

Worth knowing