JSON Wrench

Fix "Unexpected Token" in JSON

Input
All processing happens in your browser. Your JSON is never uploaded.
Output
Paste JSON on the left. It's checked as you type. Broken JSON gets an exact error location and a one-click fix.

SyntaxError: Unexpected token ... in JSON at position N means the parser reached a character it did not expect. The message is the same for about half a dozen different mistakes, and the position is a character count, not a line number, so it rarely tells you what to change.

Paste the JSON above and JSON Wrench names the actual mistake and its line and column. In the example the key name is not in double quotes, which JavaScript allows and JSON does not.

Example

Input
{
  name: 'Ada',
  "active": true
}
Result in JSON Wrench
{
  "name": "Ada",
  "active": true
}

Decoding the common variants

The character after "Unexpected token" is usually the best clue:

  • Unexpected token < at position 0: the response is HTML, usually an error page or login redirect, not JSON. Check the HTTP status code of the request.
  • Unexpected token u at position 0 (newer engines say "undefined" is not valid JSON): you parsed undefined, usually a missing variable or an empty localStorage key.
  • Unexpected token ': single quotes. JSON strings and keys need double quotes.
  • Unexpected token } or ]: often a trailing comma before the closing bracket.
  • A letter such as n or T: an unquoted key, or a Python value like True or None.
  • Unexpected end of JSON input: the data was cut off or the response body was empty.

Finding the position

The position is counted in characters from the start of the text, including spaces and newlines, which is hard to find by eye. JSON Wrench converts it into a line and column, underlines the exact character and shows the surrounding lines with the problem highlighted.

Fixing it

For syntax mistakes, press Fix and review the list of changes. If the input is HTML or something that is not JSON at all, the fix belongs at the source: check the URL, the status code and the Content-Type of the response you are parsing.

Frequently asked questions

Why does the error say position instead of line?

JavaScript's JSON.parse reports a character offset. JSON Wrench translates it to a line and column and highlights the character for you.

Why is the message different in Chrome, Firefox and Node.js?

Each JavaScript engine words its errors differently. JSON Wrench uses its own parser, so the explanation is the same everywhere.

More JSON tools