FormatWell

Guides / JSON errors

JSON.parse: unexpected character at line 1 column 1

How it appears per engine

  • SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data (Firefox)
  • Uncaught SyntaxError: Unexpected token in JSON at position 0 (Chrome, with an invisible character)

What this error means

The document failed at the very first character — the parser could not even start. Either the content is not JSON at all (HTML, XML, plain text), or an invisible character such as a UTF-8 byte-order mark (BOM) sits in front of your data.

Common causes

1. The response is not JSON

An HTML error page, an XML feed, or plain text. Log the first 100 characters of the raw string — the answer is usually obvious.

2. A UTF-8 BOM at the start of the file

Some editors (and Windows tools like PowerShell’s Out-File) write an invisible byte-order mark (\uFEFF) before the first character. It is invisible in editors but fatal to JSON.parse.

Fails

JSON.parse(fileText); // fileText starts with an invisible \uFEFF

Works

JSON.parse(fileText.replace(/^\uFEFF/, ''));

3. Invisible or non-breaking characters from copy-paste

Zero-width spaces and non-breaking spaces travel along when copying from chats, PDFs, and rendered web pages. They look like nothing and parse like poison.

How to fix it

  1. Print JSON.stringify(raw.slice(0, 20)) — invisible characters become visible escapes like "\uFEFF".
  2. Strip a BOM before parsing, or save the file as “UTF-8 without BOM”.
  3. Re-type the first character manually if the input was pasted from a formatted source.

Related errors