Sometimes JSON appears perfectly valid but still fails when parsed. A common reason is the presence of a hidden character called the Byte Order Mark (BOM).
The Byte Order Mark is a Unicode character:
U+FEFF
It is sometimes inserted automatically by text editors or file encoders when saving files in UTF-8 format.
The JSON specification allows only a small set of whitespace characters. When a BOM appears before the JSON object, many parsers throw an error.
SyntaxError: Unexpected token in JSON
This happens because the parser encounters an invisible character before the opening brace.
{"name":"admin"}
The hidden character before the brace is the BOM.
You can remove the BOM programmatically:
function removeBOM(input) {
return input.replace(/\uFEFF/g, "");
}
However, debugging invisible characters manually is difficult.
Use the Unicode Cleaner tool to detect and remove hidden characters instantly.
The UTF-8 BOM is invisible but can cause major issues in JSON parsing. Detecting and removing hidden Unicode characters ensures reliable parsing and cleaner data pipelines.