The JSON5 Data Interchange Format 1.0.0 (March 2018) is a superset of JSON that adds syntax from ECMAScript 5.1; the values are the same (objects, arrays, strings, numbers, Booleans, null). This page follows the JSON5 specification and, for identifier names, the ECMAScript 5.1 specification, read 2026-11-12. The JSON5 specification defines strings as sequences of Unicode characters and does not name a file encoding.
Objects and arrays
- Keys may be ECMAScript 5.1
IdentifierNames without quotes ({unquoted: 1}), or strings in single or double quotes. In ECMAScript 5.1 anIdentifierNamestarts with a Unicode letter,$,_or a\uescape, and reserved words areIdentifierNames too (onlyIdentifierexcludes them). - A single trailing comma is allowed after the last member of an object or array.
- Names within an object should be unique; with duplicates, behaviour is unpredictable.
Strings
- Strings may use single quotes; the other quote character needs no escape. The quote that opens the string, the backslash and line terminators must be escaped.
- A backslash before a line terminator (LF, CR, CR LF, U+2028 or U+2029) continues the string on the next line; neither is part of the string.
- U+2028 and U+2029 may appear unescaped, but authors should avoid them, parsers should warn and generators should escape them, since ECMAScript 5.1 does not allow them in strings.
| Escape | Character |
|---|---|
\', \", \\ | Quote, double quote, backslash |
\b, \f, \n, \r, \t, \v | Backspace, form feed, line feed, carriage return, tab, vertical tab |
\0 | NUL, when not followed by a digit |
\xHH | A character from U+0000 to U+00FF, by its 2-digit hex code |
\uHHHH | A UTF-16 code unit (pairs for characters beyond U+FFFF) |
Any other character after \ | That character itself; \1–\9 are not allowed |
Numbers
- Hexadecimal integers with
0xor0X:0xdecaf,-0xC0FFEE. - A leading or trailing decimal point:
.456,8675309.. - An explicit plus sign:
+1. - The IEEE 754 values
Infinity(optionally+Infinity),-InfinityandNaN(optionally+NaNor-NaN).
Numbers, duplicates and conformance
From the JSON5 specification (spec.json5.org, read 2026-11-13).
- Decimal numbers: an optionally signed integer part, then an optional fraction part (a point and one or more digits; the integer part may be omitted,
.456) and/or an exponent part (eorE, an optional sign, one or more digits:123e-456). - Numeric literal rules (ECMAScript 5.1 section 7.8.3, which the JSON5 grammar takes by reference for
NumericLiteral):DecimalLiteralisDecimalIntegerLiteral . DecimalDigits? ExponentPart?, or. DecimalDigits ExponentPart?, orDecimalIntegerLiteral ExponentPart?.DecimalIntegerLiteralis0or a non-zero digit (1 to 9) followed by any digits, so no leading zeros:0123is not a JSON5 number (and00is not either).ExponentPartiseorEand aSignedInteger(digits with an optional+or-).HexIntegerLiteralis0xor0Xand one or more hex digits; it has no fraction or exponent.- The source character immediately after a numeric literal must not be an
IdentifierStartor a decimal digit:3inis an error, not the two input elements3andin. - The value is made in two steps: the mathematical value (MV) is derived from the literal (for example, integer part plus fraction digits times 10-n, times 10e), then rounded. An MV of 0 gives +0; any other MV gives the Number (IEEE 754 double) value for that MV, the nearest representable double. The one latitude: if a decimal literal has more than 20 significant digits, the result may be either the value with every significant digit after the 20th replaced by 0, or that value with the 20th digit incremented. A digit is significant if it is non-zero and not in the exponent, or if it is a zero with a non-zero digit to its left and a non-zero digit (outside the exponent) to its right.
- In JSON5 the sign belongs to
JSON5Number, not to the literal (JSON5NumberisJSON5NumericLiteral,+JSON5NumericLiteralor-JSON5NumericLiteral), andInfinityandNaNare extraJSON5NumericLiteralforms, so the ES 5.1 literal rules above apply only to the decimal and hexadecimal forms.
- One value per text (section 9.2): a JSON5 text is exactly one
JSON5Value(the goal symbolJSON5TextisJSON5Value). The characters are first turned into input elements by repeated use of the lexical grammar, then parsed by a single application of the syntactic grammar; it is a syntax error if the tokens cannot be parsed as a singleJSON5Textwith no tokens left over, so1 2and{} {}are errors, while white space and comments around the value are not tokens. - Hexadecimal:
0xor0X, optionally signed, and one or more hex digits in either case (0xdecaf,-0xC0FFEE). - Special values:
Infinity(optional+),-Infinity,NaN(optional sign), spelled exactly. - Escapes: a decimal digit must not follow
\0; any other character after a backslash is kept without the backslash, except that digits 1 to 9 may not follow one ('\A\C\/\D\C'isAC/DC). - Duplicate names: an object with unique names is interoperable; with duplicates the behaviour is unpredictable, and an implementation may report the last pair only, report an error or fail to parse, or report all pairs including duplicates. Implementations may make the member order visible; those that do not depend on it are interoperable.
- Identifier names (unquoted member names) are the ECMAScript 5.1
IdentifierName: a start character (a Unicode letter,$,_or a\uXXXXescape) followed by start characters, combining marks, digits and connector punctuation, ZWNJ and ZWJ. The JSON5 text takes this by reference (its lexical grammar hasJSON5Identifier :: IdentifierName; every production not starting with “JSON5” comes from the ECMAScript 5.1 lexical grammar). ECMAScript 5.1 section 7.6 (opened 2026-11-13) defines it as follows:IdentifierName :: IdentifierStart | IdentifierName IdentifierPart.IdentifierStart :: UnicodeLetter | $ | _ | \ UnicodeEscapeSequence.IdentifierPart :: IdentifierStart | UnicodeCombiningMark | UnicodeDigit | UnicodeConnectorPunctuation | <ZWNJ> | <ZWJ>.UnicodeLetter: any character in the Unicode categories Uppercase letter (Lu), Lowercase letter (Ll), Titlecase letter (Lt), Modifier letter (Lm), Other letter (Lo) or Letter number (Nl).UnicodeCombiningMark: Non-spacing mark (Mn) or Combining spacing mark (Mc).UnicodeDigit: Decimal number (Nd).UnicodeConnectorPunctuation: Connector punctuation (Pc).- Characters in those categories in Unicode 3.0 must be treated as such by every conforming ECMAScript implementation; implementations may recognise characters from later Unicode editions, and for portability only Unicode 3.0 characters should be used.
- A
\escape contributes one character, the escape’s character value, and the escaped character must itself be legal at that position: replacing the escape by its character must still give a validIdentifierNamewith the same characters. - Comparison is by code units only: canonically equivalent names are not equal unless the code unit sequences are identical (the standard expects the text to have been normalised to form C beforehand).
ReservedWords fromIdentifierbut not fromIdentifierName, so keywords such asforare valid unquoted JSON5 names. - Parsers must accept every text that conforms to the grammar and may accept non-JSON5 forms or extensions; an implementation may limit the size of texts, the nesting depth, the range and precision of numbers, and the length and character contents of strings. Generators must produce text that strictly conforms to the grammar. The words MUST, SHOULD and so on follow RFC 2119 though not written in capitals; all of the text is normative except examples, notes and sections marked non-normative.
- Comments may stand before and after any token, and white space too; multi-line comments do not nest.
Comments and white space
// …and block comments/* … */(not nested).The example is the one from the specification. The specification names no media type, and IANA’s register of media types (read 2026-11-12) has no
application/entry for JSON5.