My JSON file saved from Notepad or Excel fails in another program with an error at the very first character. Why?

Most likely an invisible mark at the start of the file called a byte order mark (BOM). Some editors add it when saving as UTF-8, and programs that read JSON strictly reject it. The JSON formatter tells you when the text starts with that mark, ignores it and leaves it out of the output, so the file you download is clean.

Published · 3 min read

A character you cannot see

The byte order mark is one invisible character, U+FEFF, placed at the start of a file to announce that it is UTF-8. In the file it takes three bytes before the first brace. Almost no editor shows it, so the file looks perfectly fine, and the error points to line 1, column 1, where you see nothing wrong at all.

The JSON standard does not allow programs to add this mark and leaves them free to ignore it when reading. Some programs skip it silently and some reject the file, which is why the same file can work in one place and fail in another.

Where it comes from

  • Text editors that offer 'UTF-8 with BOM' when saving, or use it by default in some versions. Recent Windows Notepad, for example, offers both, so look at which one you picked when saving.
  • A text file you exported from a spreadsheet as UTF-8 and then edited into JSON by hand: some spreadsheet programs put the mark in the text files they export.
  • Older scripts and systems that write their files with the mark.

What the tool does

A small example: the text {"a":1} preceded by the mark. The input is 10 bytes: three for the mark and seven for the text. The tool shows a notice that the text starts with a byte order mark, which JSON does not allow, and that it ignored it and left it out of the output. Minified, the output is just 7 bytes:

{"a":1}

An Arabic example: {"name":"قهوة"} with the mark is 22 bytes, and 19 without. The difference is always three bytes, the size of the mark. The tool removes nothing else and repairs no other error: if the file has a real mistake after the mark, you will see it with its line and column.

The steps

  1. Open the JSON formatter and validator, press 'Open a JSON file' and choose the file, or paste its contents.
  2. If the BOM notice appears, that confirms the cause. If you opened the file with the button, the browser may already drop the mark while reading the file, so no notice appears; the result is the same.
  3. Make sure the tool says 'Valid JSON'.
  4. Press 'Download .json': the downloaded file starts directly with the brace, with no mark.
  5. Use the downloaded file in the program that rejected the original.

Avoiding it next time

In your editor, choose plain 'UTF-8' when saving, not 'UTF-8 with BOM'. And if your data started as a table, convert it to JSON directly with the CSV and JSON converter instead of hand-editing a text file, which skips the editor save step entirely.

Common questions

Does the tool add the mark to the downloaded file?

No. The download is UTF-8 text that starts with the first character of the JSON.

Is an error at line 1, column 1 always the BOM?

No. It can be a comment at the top of the file or a stray character. The tool tells you explicitly when the mark is the cause.

Is the file uploaded when I open it with the button?

No. It is read inside your browser and not uploaded anywhere.