SyntaxError: Unexpected token ï in JSON at position 0: what it means and how to fix it
Troubleshoot SyntaxError: Unexpected token ï in JSON at position 0 quickly and validate JSON locally (no upload).
What the error means
SyntaxError: Unexpected token ï in JSON at position 0 means the parser expected valid JSON but encountered a character/token that cannot appear there. In practice, it usually means the input is not JSON (or not strict JSON), or it is incomplete.
Most common real-world causes
- The payload starts with a UTF-8 BOM (byte order mark) or an invisible leading character before '{' or '['.
- The file/export was saved as UTF-8 with BOM and your pipeline doesn't strip it.
- You decoded bytes with the wrong encoding (BOM bytes can appear as the visible prefix '').
- You are parsing a non-UTF-8 text file (UTF-16/Windows-1251/etc.) as UTF-8.
Fast debugging steps
- Print the first characters (and their char codes) to confirm BOM/leading junk.
- Strip BOM and retry parsing (U+FEFF or the literal '' prefix).
- If you read from file/bytes, decode using the correct encoding (Python: utf-8-sig can strip BOM).
- Validate the cleaned JSON locally before any further processing (no upload).
Code example (node)
// Strip UTF-8 BOM (U+FEFF) and the common '' prefix before JSON.parse
const stripBom = (s) => s.replace(/^\uFEFF/, '').replace(/^\u00EF\u00BB\u00BF/, '');
const res = await fetch(url);
const text = await res.text();
const cleaned = stripBom(text);
const data = JSON.parse(cleaned);
Fix without uploading data
If the JSON contains sensitive data, validate and fix it locally. No Upload Tools runs 100% in your browser.
- JSON Validator to pinpoint the exact syntax error.
- JSON Repair to remove comments/trailing commas when the source is not strict.
- JSON Formatter to pretty-print and inspect structure.
- JSON String Escape if the issue is inside a string (newlines/tabs/quotes).
Workflow: validate -> fix the first error -> validate again -> export/convert.
FAQ
Does the exact token matter? Yes. The token often hints at the root cause: < is usually HTML, u is often undefined, and / often points to comments.
Should I just regex-fix JSON? Avoid blind regex edits. Validate after each change so you know what you fixed and what broke.