JSON Parse Error: Unexpected Token

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.

Common Causes

Unexpected token }

This usually means there is a trailing comma before a closing brace.

{
  "name": "Ava",
}

Unexpected token '

This usually means the JSON uses single quotes instead of double quotes.

{'name': 'Ava'}

Unexpected token n

This can happen when a key is unquoted.

{name: "Ava"}

Unexpected token <

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>

How to Fix It

  1. Paste the text into the JSON Formatter.
  2. Click Format and read the line and character position.
  3. Check the character before the reported token for a missing comma, extra comma, or unclosed string.
  4. Use Auto-fix for common issues such as trailing commas, comments, single quotes, and unquoted keys.
  5. If the text starts with <, check your API request because the response is probably HTML, not JSON.

Tip for API Debugging

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