title: How do I discover the encoding of a JSON message?
body: <p><a href="https://www.rfc-editor.org/rfc/rfc7159.html" rel="nofollow noreferrer">JSON's official specification</a> says:</p>
  <blockquote>
  <p>JSON text SHALL be encoded in UTF-8, UTF-16, or UTF-32.  The default encoding is UTF-8, and...</p>
  </blockquote>
  <p>So, essentially the JSON message can come in any of those three encodings. But... how do I <em>guess</em> which one is it when I receive it?</p>
  <p>The message can come from multiple sources, such as a queue, from the browser, from the database, the file system, etc.</p>
  <p>It also says to ignore Byte Order Masks (BOM):</p>
  <blockquote>
  <p>...implementations that parse JSON texts MAY ignore the presence of a byte order mark rather than treating it as an error.</p>
  </blockquote>
  <p>I remember XML docs had a &quot;prolog&quot; that specified the encoding, but I can't find anything similar for JSON messages.</p>
  <p>Any ideas?</p>