Notes on ECMAScript 5.1 Specification, Section 15.12.1

Section 15.12 describes the JSON Object.

15.12.1 The JSON Grammar

https://262.ecma-international.org/5.1/#sec-15.12.1.1https://262.ecma-international.org/5.1/#sec-15.12.1.1

JSON has a specific syntax. JSON.stringify returns a string that conforms to this syntax, while JSON.parse expects to receive a string that follows this syntax.

15.12.1.1 The JSON Lexical Grammar

  • JSONWhiteSpace
    • <TAB> (\t)
    • <CR> (\r)
    • <LF> (\n)
    • <SP> (\u0020)
  • JSONString
    • " JSONStringCharacters(opt) "
      • JSONStringCharacters
        • JSONStringCharacter JSONStringCharacters(opt)
          • For example, in a string like "hello world":
            • " (double quote) is required
            • hello world can be any characters except ", , or control characters (U+0000 through U+001F)
            • " (double quote) is required
          • JSONStringCharacter
            • SourceCharacter but not one of " or \ or U+0000 through U+001F
          • JSONEscapeSequence
            • Either JSONEscapeCharacter or UnicodeEscapeSequence
              • JSONEscapeCharacter can be any of the following:
                • \" (double quote)
                • \/ (forward slash)
                • \\ (backslash)
                • \b (backspace)
                • \f (form feed)
                • \n (newline)
                • \r (carriage return)
                • \t (tab)
              • UnicodeEscapeSequence is \
  • JSONNumber
    • -(opt) DecimalIntegerLiteral JSONFraction(opt) ExponentPart(opt)
      • For example, in a number like -123.45e+6:
        • - (minus sign) is optional for non-negative numbers
        • 123 (integer part) is required
        • .45 (fraction part) is optional
        • e+6 (exponent part) is optional
  • JSONNullLiteral
    • NullLiteral
  • JSONBooleanLiteral
    • BooleanLiteral

15.12.1.2 The JSON Syntactic Grammar

https://262.ecma-international.org/5.1/#sec-15.12.1.2https://262.ecma-international.org/5.1/#sec-15.12.1.2

The syntax appears to be structured as follows.

  • JSONText
    • JSONValue
      • JSONNullLiteral
      • JSONBooleanLiteral
      • JSONObject
        • { }
        • { JSONMemberList }
          • JSONMember (key-value pair)
            • JSONString : JSONValue
            • JSONMemberList
              • JSONMember
              • JSONMemberList , JSONMember
      • JSONArray
        • [ ]
        • [ JSONElementList ]
          • JSONValue
          • JSONElementList , JSONValue
      • JSONString
      • JSONNumber

While I hadn't thought about it deeply before, it makes sense that it can be represented this way.