Re:Amazon open-sources Ion – a binary and text interchangabl...
by jrgv on Friday April 22, 2016 @03:44AM
(#11547621)
> But if we take it to mean code point, then if the value is a surrogate… what should happen?
Surrogates are code points. The spec does not say what should happen if the surrogate is invalid (for example, if only the first surrogate of a surrogate pair is present), but neither does the JSON spec.
Java internally also represents non-BMP code points using surrogates. So, simply appending the surrogates to the string should yield a valid Java string if the surrogates in the input are valid.
JSON's string literals come from JavaScript, and JavaScript only sortof has a Unicode string type. So the \u escape in both languages encodes a UTF-16 code unit, not a code point. That means in JSON, the single code point U+1f4a9 "Pile of Poo" is encoded thusly:
JSON specifically says this, too, Now, Ion's spec says only: But if we take it to mean code point, then if the value is a surrogate… what should happen?Looking at the code, it looks like the above JSON will parse:
My Java isn't that great though, so I'm speculating. But I'm not sure what should happen.This is just one of those things that the first time I saw it in JSON/JS… a part of my brain melted. This is all a technicality, of course, and most JSON values should work just fine.