JSON superset — ES2019 is coming…
In my last post, I mentioned how JavaScript is evolving fast and listed all the features that will be standardized in the language in the next release this year.
Today I want to talk about JSON superset, so just to keep track of what I've talked so far, here goes the list of the ES2019 (or ES10) features:
- ̶O̶p̶t̶i̶o̶n̶a̶l̶ ̶C̶a̶t̶c̶h̶ ̶b̶i̶n̶d̶i̶n̶g̶
- JSON Superset
- Object.fromEntries
- Symbol.prototype.description
- Function.prototype.toString revision
- Well-formed JSON.stringify
- String.prototype.{trimStart,trimEnd}
- Array.prototype.{flat,flatMap}
- String.prototype.matchAll
JSON Superset
We all know JSON as a lightweight format for data interchange. It's widely used as it's very simple to read and parse, besides also supporting types, objects, and arrays.
Basically, JSON was intended to be a subset inJSON.parse
(as ECMAScript claims) but that is not true because JSON strings can contain unescaped U+2028 LINE SEPARATOR and U+2029 PARAGRAPH SEPARATOR characters while ECMAScript strings can't.
This proposal comes to solve this issue, so we don't need to use an escape sequence to put these 'special chars' into a string anymore.
Before that, the following code would throw an error:
Now, this issue will be gone!
Essentially, they extended the DoubleStringCharacter and SingleStringCharacter productions of ECMA-262 to allow unescaped U+2028 LINE SEPARATOR and U+2029 PARAGRAPH SEPARATOR characters. That's it! Pretty simple, right?