Skip to content

db add-bulk --file: parser fails on JSON file with UTF-8 BOM #54

@DidelotK

Description

@DidelotK

Description

notion db add-bulk <db-id> --file items.json fails to parse a JSON file that has a UTF-8 BOM (EF BB BF bytes at the start). Error:

Error: parse JSON: invalid character 'ï' looking for beginning of value
(expected array of {"Key": "Value"} objects)

The character ï is what the BOM bytes look like when interpreted as Latin-1.

Repro on Windows

# PowerShell 5.1 defaults to UTF-8-with-BOM when writing JSON files
$items = @(@{ Name = "test"; Status = "TBD" })
$items | ConvertTo-Json | Out-File -Encoding utf8 items.json
notion db add-bulk <db-id> --file items.json
# → Error: parse JSON: invalid character 'ï' ...

Workaround

Write the file without BOM:

[System.IO.File]::WriteAllText(
  "items.json",
  ($items | ConvertTo-Json),
  (New-Object System.Text.UTF8Encoding $false)
)

Expected

The JSON parser should skip a leading UTF-8 BOM. This is a common Windows export artifact and most modern JSON parsers handle it transparently.

In Go, the typical fix is:

data, _ := os.ReadFile(path)
data = bytes.TrimPrefix(data, []byte("\xef\xbb\xbf"))
// then json.Unmarshal(data, ...)

Environment

  • OS: Windows 11
  • Shell: PowerShell 5.1 (writes UTF-8 with BOM by default)
  • notion-cli: v0.7.0

Impact

Real friction on Windows. Bulk adds and other --file commands are blocked until the user finds the right encoding incantation.

The same problem likely affects all --file flags that read JSON (db query --filter-json @file, api ... --body @file, etc. if any). Worth fixing in a shared input-loading helper.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions