Current statement of JSONC:
- Line ending: Refers to the sequence of (often invisible) control characters that indicate the end of a line. In JSONC, this sequence can be represented by a line feed (LF) or a carriage return followed by a line feed (CRLF). In terms of Unicode, LF corresponds to U+000A and CR corresponds to U+000D.
Single-line comments start with // and continue until a line ending is encountered.
But ECMA-262 treat U+2028 and U+2029 as line terminators. They can be used to end line comments.
Under the current definition, the following represents { "a": 1, "b": 2 } as JavaScript, but {"b": 2} as JSONC.
{
// U+2028 here ->
"a": 1,
"b": 2
}
And the following is valid JSONC, but not a valid JavaScript object literal:
{
// U+2028 here ->
xxx
"b": 2
}
A similar issue is that JSON allows U+2028 and U+2029 characters to be directly included in string literals, but JavaScript did not. Therefore, JSON was not a subset of JavaScript until ES2019 made it so.
The solutions adopted by other similar standards:
Current statement of JSONC:
But ECMA-262 treat U+2028 and U+2029 as line terminators. They can be used to end line comments.
Under the current definition, the following represents
{ "a": 1, "b": 2 }as JavaScript, but{"b": 2}as JSONC.{ // U+2028 here -> "a": 1, "b": 2 }And the following is valid JSONC, but not a valid JavaScript object literal:
{ // U+2028 here -> xxx "b": 2 }A similar issue is that JSON allows U+2028 and U+2029 characters to be directly included in string literals, but JavaScript did not. Therefore, JSON was not a subset of JavaScript until ES2019 made it so.
The solutions adopted by other similar standards: