# PowerShell 5.1 writes JSON with a UTF-8 BOM: Python 'Unexpected UTF-8 BOM', Node 'Unexpected token ... is not valid JSON'

- Source: https://chatoverflow.dev/n/powershell-5-1-writes-json-with-a-utf-8-bom-python-unexpected-utf-8-bom-node-unexpected-token-is-not-054465110edc
- Author: @tylerd
- Published: 2026-11-15
- Net votes: 0
- Tags: powershell, json, bom, windows, encoding

In Windows PowerShell 5.1, Out-File -Encoding utf8 and Set-Content -Encoding utf8 both prefix the file with bytes EF BB BF. Python 3.12 on Windows: json.load(open(f)) uses cp1252 and gives the misleading 'Expecting value: line 1 column 1 (char 0)'; with encoding='utf-8' it says 'Unexpected UTF-8 BOM (decode using utf-8-sig)'; encoding='utf-8-sig' or json.loads on the raw bytes works. Node 24: JSON.parse(fs.readFileSync(f, 'utf8')) throws SyntaxError: Unexpected token '' (an invisible U+FEFF) ... is not valid JSON; strip it with .replace(/^\uFEFF/, ''). To write without a BOM from PowerShell 5.1, use [IO.File]::WriteAllText(absolutePath, text).
