The JSON5 Grammar
This document is deprecated. For an up to date grammar, see https://github.com/json5/json5-spec
JSON5.stringify
produces a String that conforms to the following JSON5
grammar. JSON5.parse
accepts a String that conforms to the JSON5 grammar.
JSON5 is similar to ECMAScript source text in that it consists of a sequence of characters conforming to the rules of SourceCharacter. The JSON5 Lexical Grammar defines the tokens that make up a JSON5 text similar to the manner that the ECMAScript lexical grammar defines the tokens of an ECMAScript source test. The JSON5 lexical grammar shares some productions with the ECMAScript lexical grammar. All nonterminal symbols of the grammar that do not begin with the characters "JSON5" are defined by productions of the ECMAScript lexical grammar, with the following exception: when ECMAScript references its LineTerminator and LineTerminatorSequence productions, substitute them with the JSON5LineTerminator and JSON5LineTerminatorSequence productions defined here, respectively.
JSON5WhiteSpace ::
<TAB>
<SP>
<NBSP>
<BOM>
JSON5LineTerminator ::
<LF>
<CR>
JSON5LineTerminatorSequence ::
<LF>
<CR> [lookahead ∉ <LF> ]
<CR> <LF>
JSON5Comment ::
JSON5Identifier ::
JSON5IdentifierStart
JSON5Identifier JSON5IdentifierPart
JSON5IdentifierStart ::
JSON5Letter
$
_
JSON5IdentifierPart ::
JSON5IdentifierStart
JSON5Letter
A
throughZ
ora
throughz
JSON5NullLiteral ::
JSON5BooleanLiteral ::
JSON5Number ::
JSON5String ::
The JSON5 Syntactic Grammar defines a valid JSON5 text in terms of tokens defined by the JSON5 lexical grammar. The goal symbol of the grammar is JSON5Text.
JSON5Text :
JSON5Value
JSON5Value :
JSON5NullLiteral
JSON5BooleanLiteral
JSON5Object
JSON5Array
JSON5String
JSON5Number
JSON5Object :
{
}
{
JSON5MemberList,
opt}
JSON5MemberList :
JSON5Member
JSON5MemberList
,
JSON5Member
JSON5Member :
JSON5MemberName
:
JSON5Value
JSON5MemberName :
JSON5Identifier
JSON5String
JSON5Array :
[
]
[
JSON5ElementList,
opt]
JSON5ElementList :
JSON5Value
JSON5ElementList
,
JSON5Value
Some additional functionality has been planned for JSON5, but due to
limitations, has not yet been implemented. The following non-normative additions
may be supported by implementations of JSON5.parse
, however all
implementations of JSON5.stringify
must conform to the normative syntax.
ECMAScript allows for certain Unicode characters, and Unicode escape sequences representing those characters, to be included in identifiers. The syntax and semantics of JSON5 can be extended as follows:
JSON5Identifier ::