Portrait Dr. Axel Rauschmayer
Dr. Axel Rauschmayer
Homepage | Twitter
Cover of book “Exploring ES6”
Book, exercises, quizzes
(free to read online)
Logo of newsletter “ES.next news”
Newsletter (free)
Cover of book “JavaScript for impatient programmers”
Book (free online)

ES proposal: JSON superset

[2019-01-29] dev, javascript, es2019, json
(Ad, please don’t block)

The proposal “JSON superset” (by Richard Gibson) is at stage 4 and therefore part of ECMAScript 2019. This blog post explains how it works.

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:
    const sourceCode = '"\u2028"';
    eval(sourceCode); // SyntaxError
    
  • JSON string literals can contain these two characters:
    const json = '"\u2028"';
    JSON.parse(json); // OK
    

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.