JSON Errors / JavaScript (Firefox)

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

How to Fix: SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

This is Firefox's wording for a JSON.parse() failure at the very first character - Chrome reports the same problem as "Unexpected token ... at position 0". The document is wrong from the start: it is not a matter of a typo deeper in your JSON.

What that first character is determines the fix: "<" means HTML came back, "u" usually means the string "undefined", "[object" means an object was coerced to a string, and an invisible character often means a BOM (byte-order mark).

{"find": "error"}paste your JSON below

Common causes

1. HTML response instead of JSON

An error page or redirect returned HTML. The first character "<" is invalid JSON immediately.

2. Byte-order mark (BOM) at the start of a file

Files saved as "UTF-8 with BOM" (common from Windows editors) start with an invisible \uFEFF character that JSON.parse rejects at line 1 column 1 even though the file looks perfect.

Invalid
\uFEFF{"name": "Ada"}   // looks identical to valid JSON in an editor

3. Empty or undefined input

Parsing "", null coerced to "null"... wait - null parses fine; but undefined coerces to the string "undefined", which fails at the "u" in column 1.

How to fix it

Strip a BOM before parsing (JavaScript)
const data = JSON.parse(raw.replace(/^\uFEFF/, ""));

// Node.js: read the file without a BOM
import { readFileSync } from "fs";
const raw = readFileSync("config.json", "utf8").replace(/^\uFEFF/, "");
Reveal the invisible first character
console.log(raw.charCodeAt(0));
// 65279 (0xFEFF) = BOM  |  60 = "<" (HTML)  |  117 = "u" ("undefined")

Frequently asked questions

The JSON looks perfectly valid in my editor. What now?

Invisible characters are the usual culprit: a BOM at the start, non-breaking spaces (U+00A0) instead of regular spaces, or "smart quotes" from a word processor. Log charCodeAt(0) for the first character, or paste the content into the validator on this page - it will pinpoint the offending character.

Why does Chrome show a different message for the same bug?

Each JavaScript engine words its JSON errors differently: SpiderMonkey (Firefox) says "unexpected character at line 1 column 1", V8 (Chrome/Node) says "Unexpected token" or the newer "... is not valid JSON". Same parser rules, different phrasing.

How do I save JSON without a BOM?

In VS Code the default "UTF-8" encoding has no BOM (avoid "UTF-8 with BOM" in the encoding picker on the status bar). In Notepad choose "UTF-8" rather than "UTF-8 with BOM" in Save As. Most build tools and linters can also strip BOMs automatically.

Last updated:

Related JSON errors

You might also need

Free and in-browser, like everything on JSON Console. Browse all tools →