<div dir="ltr"><div><a href="https://en.wikipedia.org/wiki/Byte_order_mark#Usage">https://en.wikipedia.org/wiki/Byte_order_mark#Usage</a></div><div><br></div><div>There is some pertinent advice on that page.</div><div>There is also a note that Visual Studio uses/used the BOM to see if a file is UTF8 vs whatever else.</div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Aug 19, 2019 at 3:46 PM Ben Boeckel &lt;<a href="mailto:ben.boeckel@kitware.com">ben.boeckel@kitware.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Mon, Aug 19, 2019 at 22:25:05 +0300, Henri Sivonen wrote:<br>
&gt; On Mon, Aug 19, 2019 at 9:57 PM Ben Boeckel &lt;<a href="mailto:ben.boeckel@kitware.com" target="_blank">ben.boeckel@kitware.com</a>&gt; wrote:<br>
&gt; &gt; Notepad?<br>
&gt; <br>
&gt; Yes, Notepad. It&#39;s generally easier to make parsers of all kinds (XML<br>
&gt; before, JSON later) accept the UTF-8 BOM than to fight Notepad. It&#39;ll<br>
&gt; take a long time for the existing installed base to get replaced with<br>
&gt; the newest: <a href="https://mobile.twitter.com/JenMsft/status/1163474010509701120" rel="noreferrer" target="_blank">https://mobile.twitter.com/JenMsft/status/1163474010509701120</a><br>
<br>
BOMs only make sense in an at-rest storage backed JSON file that the<br>
parser reads directly. Given a string, a JSON parser should *certainly*<br>
not accept a BOM leader.<br>
<br>
Quick survey:<br>
<br>
    % echo $&#39;\xEF\xBB\xBF{}&#39; &gt; bom.json<br>
<br>
  - jsoncpp: no mention of a BOM in the source, probably unhappy about<br>
    it<br>
  - jq: fine<br>
  - python3:<br>
    json.decoder.JSONDecodeError: Unexpected UTF-8 BOM (decode using utf-8-sig): line 1 column 1 (char 0)<br>
  - ruby:<br>
    /usr/share/ruby/json/common.rb:156:in `parse&#39;: 765: unexpected token at &#39;\xEF\xBB\xBF{}&#39; (JSON::ParserError)<br>
  - C#: <a href="https://jimmybogard.com/the-curious-case-of-the-json-bom/" rel="noreferrer" target="_blank">https://jimmybogard.com/the-curious-case-of-the-json-bom/</a><br>
<br>
I don&#39;t know that BOM support is actually all that wide-spread in<br>
readers based on this short survey. And the solution seems to be &quot;don&#39;t<br>
write the BOM&quot; where the problem is encountered.<br>
<br>
I think those sticking to their notepad guns are just going to have to<br>
wait for something better because waiting for the libraries to catch up<br>
(and the relevant fixes to be backported to declared minimum supported<br>
versions) is likely going to take *even longer*. Or they can download a<br>
real editor and actually contribute to whatever codebase they&#39;re trying<br>
to build.<br>
<br>
&gt; &gt; &gt; 2. Consistency with Web browsers.<br>
&gt; &gt;<br>
&gt; &gt; I don&#39;t see why a web browser would care about these files.<br>
&gt; <br>
&gt; Maybe not _these_ JSON files, but a general-purpose JSON parser can<br>
&gt; still care about consistency with Web browsers.<br>
<br>
That&#39;s fine. They can then accept the not-BOM files that every writer<br>
for this format would write just like every other BOM-less<br>
network-transferred JSON content in the world.<br>
<br>
--Ben<br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>Be seeing you,<br></div>Tony<br></div></div>