Skip to content

fix: handle BOM in JSON parsing#1753

Open
coldworld22 wants to merge 1 commit intotypicode:mainfrom
coldworld22:fix/json-bom-handling
Open

fix: handle BOM in JSON parsing#1753
coldworld22 wants to merge 1 commit intotypicode:mainfrom
coldworld22:fix/json-bom-handling

Conversation

@coldworld22
Copy link
Copy Markdown

This PR fixes an issue where JSON files containing a BOM (Byte Order Mark) cause a SyntaxError during parsing.

Cause

lowdb's JSONFile adapter uses JSON.parse directly, which fails when encountering BOM characters.

Solution

Replaced JSONFile with DataFile and introduced a custom parse function that strips BOM before parsing.

This ensures compatibility with UTF-8 BOM encoded JSON files without modifying the file on disk.

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.

1 participant