JSON WalletPrivacy-first JSON & API workspace

Fix "Unexpected token in JSON at position N"

JavaScript / Node.js ยท JSON error

โ† All tools

Unexpected token < in JSON at position 0Unexpected token o in JSON at position 1Unexpected token 'x', "..." is not valid JSONSyntaxError: Unexpected token in JSON at position N

Opens the editor with a broken example loaded and repaired, entirely in your browser โ€” nothing is uploaded.

What causes it

This is the error JSON.parse() (and fetch().then(r => r.json())) throws when it reaches a character that cannot legally appear at that point in the text. The position is the zero-based character index of the offending token, and the token itself is the biggest clue:

  • Unexpected token < at position 0 โ€” the response is HTML, not JSON. You are almost certainly parsing an error page (a 404 or 500) or a login redirect instead of the API payload. Check the network response and the status code.
  • Unexpected token o at position 1 โ€” you called JSON.parse() on something that is already a JavaScript object. The o comes from the word [o]bject when the object is coerced to a string. Remove the extra parse.
  • Any other token โ€” a genuine syntax mistake such as a trailing comma, a single quote, an unquoted key, or a missing bracket at that position.

How to fix it

  1. Log the raw response text before parsing and confirm it actually is JSON (not HTML or empty).
  2. If it starts with "<", you are parsing an HTML error page โ€” fix the request URL, auth, or status handling instead.
  3. If the token is "o" at position 1, remove the redundant JSON.parse() โ€” the value is already an object.
  4. Otherwise, paste the text into JSON Wallet to jump to the exact position and repair trailing commas, single quotes, or missing brackets.

Before and after

Broken:

{
  "name": "Ada",
  "roles": ["admin",]
}

Fixed:

{
  "name": "Ada",
  "roles": ["admin"]
}

Want to fix your own JSON instead of the example? Open the editor, paste it in, and click Repair โ€” it runs entirely in your browser.

Frequently asked questions

What does "Unexpected token < in JSON at position 0" mean?

The very first character is <, so the response is HTML, not JSON. You are parsing an error page, a redirect, or an empty body. Inspect the network tab and the HTTP status code before calling .json().

Why do I get "Unexpected token o in JSON at position 1"?

You passed an object (not a string) to JSON.parse(). It gets stringified to [object Object], and the parser trips on the o. The value is already parsed โ€” use it directly.


Related JSON errors

For a full reference of JSON mistakes, read Common JSON errors and how to fix them.

Press โŒ˜ K for commands