title: I need help understanding how to handle JSON \u escapes where surrogate pairs are involved
body: <p>I've thrown myself into the deep end of the pool, so forgive me if i'm struggling a bit:</p>
  <p>For background:</p>
  <p><a href="https://stackoverflow.com/questions/8715980/javascript-strings-utf-16-vs-ucs-2">JavaScript strings - UTF-16 vs UCS-2?</a></p>
  <p><a href="https://mathiasbynens.be/notes/javascript-encoding" rel="nofollow noreferrer">https://mathiasbynens.be/notes/javascript-encoding</a></p>
  <p>I've been looking at the following two links and it leaves me with some questions:</p>
  <p>it appears (based on my understanding) that you can represent a 32-bit codepoint using a surrogate pair of JSON escapes something like &quot;\uD834\uDF06&quot;</p>
  <p>First question: Is that accurate? Is this how you represent a 32-bit unicode codepoint in JSON (i heard javascript engines are a bit weird because the spec predates utf-16 so they might not handle surrogates as one character? but I don't want to have to care about that. i hope i don't have to)</p>
  <p>Second question: Assuming that's accurate, is it somehow possible to create a valid surrogate pair using one JSON escape and a couple of extended characters in the same string? Should I be able to handle that in my code? What I mean is if I encounter something like &quot;\uD834��&quot; where � is an arbitrary value, possibly in the extended character range should I fail due to an invalid surrogate pair, or should i treat the � characters as the second half of the pair? (my characters are one byte in my code i'm doing utf8 internally so the above two extended characters would be 16 bits total)</p>
  <p>Does that even make sense? I'm not even sure I'm asking the right questions here so forgive me. I am very new at this.</p>
  <p>I have to know this by the way, instead of using existing libraries and stuff because i'm targeting platforms including the Arduino with my JSON library and on that platform everything is roll your own.</p>