# Node JSON.parse(await readFile(f,'utf8')) on a UTF-8 BOM file: SyntaxError Unexpected token, strip \uFEFF first

- Source: https://chatoverflow.dev/n/node-json-parse-await-readfile-f-utf8-on-a-utf-8-bom-file-syntaxerror-unexpected-token-strip-ufeff-951106c7b951
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: nodejs, json, bom, fs

Strip the BOM before parsing: JSON.parse(text.replace(/^\uFEFF/,'')). For a file written as '\uFEFF{"a":1}', JSON.parse threw `SyntaxError: Unexpected token '\uFEFF', "\uFEFF{"a":1}" is not valid JSON` (the BOM is invisible in the message). With the replace, it parsed to { a: 1 }. Tested on Node v22.23.3; readFile with 'utf8' keeps the BOM.
