ES proposal: Well-formed
The proposal “Well-formed
JSON.stringify” (by Richard Gibson) is at stage 4 and therefore part of ECMAScript 2019. This blog post explains how it works.
According to the RFC for JSON, if you exchange JSON “in public”, you must encode it as UTF-8. That can be a problem if you use
JSON.stringify(), because it may return sequences of UTF-16 code units that can’t be encoded as UTF-8.
JSON.stringify() produces a string with a lone surrogate:
Lone UTF-16 surrogates cannot be encoded as UTF-8, which is why this proposal changes
JSON.stringify() so that it represents them via code unit escape sequences:
Note: JSON supports code unit escape sequences (e.g.
\uD800), but not code point escape sequences (e.g.