20. JSON superset
This chapter covers the ES2019 feature “JSON superset” by Richard Gibson) is at [stage 4](http://exploringjs.com/es2016-es2017/ch_tc39-process.html.
At the moment, JSON (as standardized via ECMA-404) is not a subset of ECMAScript:
- Until recently, ECMAScript string literals couldn’t contain the characters U+2028 LINE SEPARATOR and U+2029 PARAGRAPH SEPARATOR (you had to use an escape sequence to put them into a string). That is, the following source code produced a syntax error:
- JSON string literals can contain these two characters:
Given that the syntax of JSON is fixed, a decision was made to remove the restriction for ECMAScript string literals. That simplifies the grammar of the specification, because you don’t need separate rules for ECMAScript string literals and JSON string literals.
当前内容版权归 exploringjs.com 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 exploringjs.com .