Skip to content

Conversation

@MirrorDNA-Reflection-Protocol

Summary

Fixes #1631 — JSON files with UTF-8 BOM (byte order mark) cause SyntaxError: Unexpected token because the invisible BOM character (U+FEFF) is not valid JSON.

Problem

Some text editors (especially on Windows like Notepad) add a UTF-8 BOM at the start of files. This invisible character causes JSON.parse to fail:

SyntaxError: Unexpected token '', "{   "pos"... is not valid JSON

Solution

This PR adds BOM detection and stripping before JSON parsing:

  • Checks if the first character is U+FEFF (BOM)
  • If present, strips it from the content
  • Writes the cleaned content back to the file (one-time fix)

Testing

Tested by creating a JSON file with BOM - the server now starts correctly instead of throwing a parse error.

Some editors (especially on Windows) add a UTF-8 BOM (byte order mark,
U+FEFF) at the start of files. This invisible character causes JSON.parse
to fail with 'Unexpected token' error.

This fix detects the BOM and strips it from the file content before
the JSON parser sees it, preventing the parse error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SyntaxError: Unexpected token '', "{ "pos"... is not valid JSON

1 participant