JSON6 Syntax Reference

Complete syntax rules and production definitions for the JSON6 data format.

TL;DR: JSON6 syntax follows ECMAScript 5.1 conventions. Objects use curly braces, arrays use brackets, strings can be single or double quoted, and comments use JavaScript-style // or /* */ syntax.

JSON6 Values

A JSON6 document consists of a single JSON6 value, which can be any of the following types:

Object

Key-value pairs

Array

Ordered list

String

Text data

Number

Numeric data

Boolean

true or false

Null

No value

Value Production

JSON6Value: JSON6Null JSON6Boolean JSON6String JSON6Number JSON6Object JSON6Array

Objects

An object is an unordered collection of zero or more name/value pairs, enclosed in curly braces {}. JSON6 objects extend JSON objects with unquoted keys, single-quoted keys, and trailing commas.

Object Syntax

{ // Unquoted keys (valid ECMAScript identifiers) unquoted: 'value', // Single-quoted keys 'single-quoted': 'allows special chars', // Double-quoted keys (JSON compatible) "double-quoted": "standard JSON", // Trailing comma allowed last: 'value', }

Object Key Rules

Unquoted Keys

Keys can be unquoted if they are valid ECMAScript 5.1 identifiers:

  • Start with: letter, _, $, or Unicode escape
  • Followed by: letters, digits, _, $, or Unicode escapes
  • Cannot be reserved words: break, case, class, etc.

Quoted Keys

Keys can use single or double quotes. This allows any string as a key, including special characters, spaces, and reserved words.

Valid vs Invalid Examples

Valid

{ name: 'value', $price: 100, _private: true, 'with-dash': 'ok', '123start': 'ok', }

Invalid

{ with-dash: 'error', 123start: 'error', class: 'reserved', has spaces: 'error', }

Object Production

JSON6Object: { } { JSON6MemberList } { JSON6MemberList , } JSON6MemberList: JSON6Member JSON6MemberList , JSON6Member JSON6Member: JSON6MemberName : JSON6Value JSON6MemberName: JSON6Identifier JSON6String

Arrays

An array is an ordered sequence of zero or more values, enclosed in square brackets []. JSON6 arrays extend JSON arrays with trailing commas.

Array Syntax

[ 'first', 'second', 'third', // trailing comma allowed ]

Nested Structures

Arrays can contain any JSON6 values, including nested objects and arrays:

[ { name: 'Alice', scores: [95, 87, 92], }, { name: 'Bob', scores: [88, 91, 85], }, ]

Array Production

JSON6Array: [ ] [ JSON6ElementList ] [ JSON6ElementList , ] JSON6ElementList: JSON6Value JSON6ElementList , JSON6Value

Strings

Strings are sequences of Unicode characters enclosed in single or double quotes. JSON6 extends JSON strings with single quotes, additional escape sequences, and multi-line support.

Quote Styles

{ double: "double-quoted string", single: 'single-quoted string', // Single quotes make it easier to include double quotes html: '<div class="container">', // Double quotes make it easier to include single quotes text: "It's a nice day", }

Escape Sequences

JSON6 supports all JSON escape sequences plus additional ones from ECMAScript 5.1:

Escape Character Unicode Notes
\' Apostrophe U+0027 JSON6 only
\" Quotation mark U+0022 JSON & JSON6
\\ Backslash U+005C JSON & JSON6
\b Backspace U+0008 JSON & JSON6
\f Form feed U+000C JSON & JSON6
\n Line feed U+000A JSON & JSON6
\r Carriage return U+000D JSON & JSON6
\t Horizontal tab U+0009 JSON & JSON6
\v Vertical tab U+000B JSON6 only
\0 Null U+0000 JSON6 only
\xHH Hex escape U+00HH JSON6 only
\uHHHH Unicode escape U+HHHH JSON & JSON6

Multi-line Strings

Strings can span multiple lines by escaping the line terminator with a backslash:

{ multiline: 'This is line one \ and this is line two \ and this is line three', }

Note: The backslash and line terminator are not included in the string value. The above example produces: "This is line one and this is line two and this is line three"

String Production

JSON6String: " JSON6DoubleStringCharacter? " ' JSON6SingleStringCharacter? ' JSON6DoubleStringCharacter: SourceCharacter but not " or \ or LineTerminator \ EscapeSequence LineContinuation U+2028 U+2029 JSON6SingleStringCharacter: SourceCharacter but not ' or \ or LineTerminator \ EscapeSequence LineContinuation U+2028 U+2029

Numbers

JSON6 numbers extend JSON numbers with hexadecimal notation, leading/trailing decimal points, explicit positive signs, and IEEE 754 special values.

Number Formats

{ // Standard JSON numbers integer: 42, negative: -17, decimal: 3.14159, exponent: 1.5e10, negativeExponent: 2.5e-5, // JSON6 extensions hexadecimal: 0xFF, hexLower: 0xdead, hexUpper: 0xBEEF, leadingDecimal: .5, trailingDecimal: 5., positiveSign: +10, positiveExponent: 1e+10, // IEEE 754 special values infinity: Infinity, negativeInfinity: -Infinity, positiveInfinity: +Infinity, notANumber: NaN, }

Number Categories

Decimal Numbers

  • 42 - Integer
  • -17 - Negative integer
  • +10 - Explicit positive (JSON6)
  • 3.14 - Decimal
  • .5 - Leading decimal (JSON6)
  • 5. - Trailing decimal (JSON6)
  • 1e10 - Exponential

Hexadecimal Numbers

  • 0xFF - Uppercase hex
  • 0xff - Lowercase hex
  • 0xDeadBeef - Mixed case
  • -0xFF - Negative hex
  • +0xFF - Positive hex (JSON6)

Special Values (JSON6 only)

  • Infinity - Positive infinity
  • -Infinity - Negative infinity
  • NaN - Not a Number (represents undefined or unrepresentable values)

Important: Infinity and NaN cannot be serialized to standard JSON. If you use these values and later need JSON output, you'll need to handle them specially (e.g., convert to null or strings).

Number Production

JSON6Number: JSON6NumericLiteral Infinity NaN JSON6NumericLiteral: NumericLiteral NumericLiteral: DecimalLiteral HexIntegerLiteral DecimalLiteral: DecimalIntegerLiteral . DecimalDigits? ExponentPart? . DecimalDigits ExponentPart? DecimalIntegerLiteral ExponentPart? HexIntegerLiteral: 0x HexDigit+ 0X HexDigit+

Comments

JSON6 supports JavaScript-style comments. Comments are completely ignored during parsing and do not affect the resulting data structure.

Single-Line Comments

Single-line comments start with // and continue to the end of the line:

{ // This is a single-line comment name: 'app', version: '1.0', // Inline comment }

Multi-Line Comments

Multi-line comments are enclosed between /* and */:

{ /* * This is a multi-line comment. * It can span multiple lines. * Useful for longer explanations. */ database: { host: 'localhost', port: 5432, }, }

Comment Placement

Comments can appear anywhere whitespace is allowed:

// File header comment { /* Before key */ key /* After key */: /* Before value */ 'value' /* After value */, array: [ // Comment in array 1, /* Another comment */ 2, ], } // Trailing comment

Note: Comments are not preserved when parsing JSON6. If you parse a JSON6 file and stringify the result, comments will be lost. This is standard behavior for data interchange formats.

Comment Production

Comment: MultiLineComment SingleLineComment MultiLineComment: /* MultiLineCommentChars? */ SingleLineComment: // SingleLineCommentChars? MultiLineCommentChars: MultiLineNotAsteriskChar MultiLineCommentChars? * PostAsteriskCommentChars? SingleLineCommentChars: SingleLineCommentChar SingleLineCommentChars? SingleLineCommentChar: SourceCharacter but not LineTerminator

Whitespace

JSON6 recognizes all whitespace characters defined by ECMAScript 5.1, providing more flexibility than JSON's limited whitespace support.

Whitespace Characters

Character Unicode Name JSON JSON6
\t U+0009 Tab
\n U+000A Line Feed
\r U+000D Carriage Return
(space) U+0020 Space
\v U+000B Vertical Tab
\f U+000C Form Feed
U+00A0 No-Break Space
U+FEFF Byte Order Mark
U+2028 Line Separator
U+2029 Paragraph Separator

Whitespace Production

WhiteSpace: <TAB> <VT> <FF> <SP> <NBSP> <BOM> <USP> LineTerminator: <LF> <CR> <LS> <PS>

Ready to Use JSON6?

Check out our language-specific guides for implementation details.