Skip to content

Conversation

@yCodeTech
Copy link
Owner

Fixes various errors brought up in comments in #14.

Changes:

File reading and parsing improvements in readJsonFile util function

  • Explicitly read files as UTF-8 encoding.
  • Remove any Byte Order Mark (BOM) from the beginning of the file (fixes Invalid Symbol parsing error).
  • Allow parsing of empty files (fixes Value Expected parsing error) - the parser needed an extra opt-in option to prevent erroring on empty files.

- Added a `allowEmptyContent: true` option in jsonc-parser's `parse` method to allow empty json files without it erroring.
- Added `encoding: "utf"` option to Node's `readFileSync` in the `readJsonFile` util function. This is to ensure files are read as utf8 encoding.

- Fixed `Invalid Symbol` parsing error. This could happen if the JSON file is saved as encoding UTF-8 with BOM, it's the BOM marker at the start of the file that fails parsing. So we remove the BOM character codes from the contents before parsing it.

ref: https://stackoverflow.com/a/24376813/2358222
@yCodeTech yCodeTech merged commit dff4d7b into master Dec 8, 2025
1 check passed
@yCodeTech yCodeTech deleted the fix/parsing-json-files branch December 8, 2025 02:09
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.

[BUG]: Extension startup crash - error: "Cannot convert undefined or null to object"

2 participants