jsonyx Specification

jsonyx allows minimal and unambiguous JSON deviations for developer convenience.

Example

{
    /* Block */ // and line comments
    "Missing commas": [1 2 3],
    "NaN and infinity": [NaN, Infinity, -Infinity],
    "Surrogates": "\ud800",
    "Trailing comma": [0,],
    "Unquoted keys": {key: "value"}
}

Grammar

Generated with RR - Railroad Diagram Generator by Gunther Rademacher.

jsonyx_document

A jsonyx document consists of a single value.

jsonyx_document ::= value
_images/jsonyx_document.svg _images/jsonyx_document1.svg

value

A value can be an object, array, string, number, true, false or null.

value ::= whitespace
          ( object | array | string | number | 'true' | 'false' | 'null' )
          whitespace
_images/value2.svg _images/value3.svg

object

An object is an unordered set of key/value pairs enclosed in curly braces. Each key is followed by a colon and pairs are separated by commas or whitespace with an optional trailing comma.

object ::= '{' (
           whitespace
           | ( ( key ':' value ) ++ ( ',' | whitespace - '' ) ) ( ',' whitespace )?
           ) '}'
_images/object.svg _images/object1.svg

array

An array is an ordered collection of values enclosed in square brackets. Values are separated by commas or whitespace with an optional trailing comma.

array ::= '[' (
          whitespace
          | ( value ++ ( ',' | whitespace - '' ) ) ( ',' whitespace )?
          ) ']'
_images/array.svg _images/array1.svg

string

A string is a sequence of characters, wrapped in double quotes, using backslash escapes.

string ::= '"' (
           [^"\#x0-#x1F]
           | '\' ( ["\/bfnrt] | 'u' [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] )
           )* '"'
_images/string2.svg _images/string3.svg

number

A number is a signed decimal number, optionally in scientific notation or one of the special values NaN, Infinity and -Infinity.

number ::= '-'? (
           ( '0' | [1-9] [0-9]* ) ( '.' [0-9]+ )? ( [eE] [+-]? [0-9]+ )?
           | 'Infinity'
           ) | 'NaN'
_images/number2.svg _images/number3.svg

key

A key can be a string or an identifier.

_images/key.svg _images/key1.svg

whitespace

Whitespace, including comments can be inserted between any pair of tokens.

whitespace ::= ( '//' [^#xA#xD]* | '/*' ( ( [^*]* '*'+ ) ++ [^*/] ) '/' | [#x9#xA#xD#x20] )*
_images/whitespace2.svg _images/whitespace3.svg