Well-formed JSON.stringify

Published · tagged with ECMAScript ES2019

JSON.stringify was previously specified to return ill-formed Unicode strings if the input contains any lone surrogates:

// → '"�"'

The “well-formed JSON.stringify” proposal changes JSON.stringify so it outputs escape sequences for lone surrogates, making its output valid Unicode (and representable in UTF-8):

// → '"\\ud800"'

Note that JSON.parse(stringified) still produces the same results as before.

This feature is a small fix that was long overdue in JavaScript. It’s one less thing to worry about as a JavaScript developer.

Feature support