Glossary of Terms
Every term you meet in the spec and around it, from ABNF to white space.
This glossary defines the vocabulary of JSON5 precisely: grammar words such as IdentifierName and line continuation, number forms such as NaN and hexadecimal literals, and library words such as reviver, replacer and round-trip.
It also places neighboring names, including JSONC, JWCC, HuJSON, Hjson, HOCON and JSONL, and the standards behind them: ECMAScript, ECMA-404, RFC 8259 and ABNF. Every entry has its own linkable anchor, a short tested example where one helps, and a primary source listed at the end of the page.
TL;DR: JSON5 is a superset of JSON borrowing syntax from ECMAScript 5.1. The terms people mix up most are JSONC (comments only, trailing commas optional), JWCC (comments and trailing commas), JSONL (one JSON value per line, unrelated to JSON5), and round-trip (the reference library keeps data, not comments).
All Terms
Each term below has its own anchor, so you can link to a single definition, for example /glossary/#identifiername. Select the # beside a heading to put that address in the browser bar.
Definitions follow the JSON5 1.0.0 specification where the term appears there. Terms about libraries describe json5 2.2.3 for JavaScript, and code results shown on this page were produced with that release on Node.js 24. Code samples assume const JSON5 = require('json5').
| If you want to know about | Start with |
|---|---|
| Object names without quotes | IdentifierName |
| Why a document fails to parse | White space, line continuation, trailing comma |
| Numbers JSON cannot write | Hexadecimal literal, Infinity, NaN, decimal points |
| Writing files back | Round-trip, lossless parser, stringify |
| Sibling formats | JSONC, JWCC, Hjson, HOCON, JSONL |
A
ABNF #
Augmented Backus-Naur Form, a notation for writing grammars, specified in RFC 5234 (STD 68, January 2008). RFC 8259 defines JSON in ABNF. The JSON5 specification does not: it writes its grammar in the notation of ECMAScript, with :: for lexical productions and : for syntactic ones.
Array #
An ordered sequence of zero or more values between square brackets, separated by commas. Elements need not share a type, and one comma may follow the last element. Empty slots such as [1,,3] are not allowed.
B
Block comment #
The spec calls it a multi-line comment. It starts with /*, ends with the first */, and may sit on one line or span many. Block comments cannot nest, so an inner */ ends the outer comment and the text after it is read as data.
{
port: /* inline */ 8080,
/* A block comment
over two lines. */
}Byte order mark (BOM) #
The code point U+FEFF. JSON5 lists it as white space, so a parser skips it before or after any token, not only at the start of a file. RFC 8259 says generators must not add one to JSON sent over a network and that parsers may ignore one instead of rejecting the text. See encoding problems.
C
Code point #
A number that Unicode assigns to a character, written U+ followed by hexadecimal digits. The distinction from a UTF-16 code unit matters for surrogate pairs: one code point above U+FFFF occupies two code units in a JavaScript string.
Conforming parser #
Section 10 of the spec asks one thing of a parser: it must accept every text that conforms to the JSON5 grammar. It may also accept forms outside the grammar, and it may limit text size, nesting depth, number range and precision, and string length and contents. So "conforming" does not by itself mean "rejects everything else".
The json5-tests repository holds valid and invalid cases, with the file extension signaling the expected result: .json and .json5 files should parse, while .js and .txt files should fail.
D
Duplicate names #
Two members of one object with the same name. The spec says names should be unique and calls the behavior otherwise unpredictable: a parser may report the last pair, fail, or report them all. The reference JavaScript library keeps the last value.
JSON5.parse('{a: 1, a: 2}'); // { a: 2 }E
ECMA-404 #
ECMA-404, "The JSON data interchange syntax", is the Ecma International standard for JSON; its second edition is dated December 2017. It defines only which texts are syntactically valid JSON, not what they mean to a program. It does not cover JSON5.
ECMAScript #
The standardized language that JavaScript implements, published as ECMA-262. JSON5 borrows from one fixed edition, ECMAScript 5.1 (June 2011), usually shortened to ES5. Later features, such as template literals or BigInt literals, are not part of JSON5. More on the ECMAScript relationship and the features left out.
Escape sequence #
A reverse solidus (backslash) followed by characters that stand for another character inside a string. JSON5 allows more of them than JSON does:
| Escape | Meaning | In JSON? |
|---|---|---|
\' | Apostrophe | |
\" \\ \/ | Quotation mark, reverse solidus, solidus | |
\b \f \n \r \t | Backspace, form feed, line feed, carriage return, tab | |
\v | Vertical tab, U+000B | |
\0 | Null, U+0000; a decimal digit must not follow | |
\xHH | Exactly two hex digits, U+0000 through U+00FF | |
\uHHHH | Exactly four hex digits, one UTF-16 code unit | |
| Backslash before any other character | The character itself, except digits 1 through 9 |
JSON5.parse("'\\x41\\u0042\\C\\/\\D'"); // 'ABC/D'
JSON5.parse("'\\1'"); // SyntaxError: invalid character '1' at 1:3
JSON5.parse("'\\u{1F600}'"); // SyntaxError: invalid character '{' at 1:4Explicit plus sign #
A number may start with + as well as -. This applies to decimal numbers, hexadecimal literals, Infinity and NaN. No white space may separate the sign from the number in the reference parser: + 1 is rejected.
JSON5.parse('+1'); // 1
JSON5.parse('+Infinity'); // Infinity
JSON5.parse('+ 1'); // SyntaxError: invalid character ' ' at 1:2G
Generator #
Software that produces JSON5 text. Section 11 of the spec requires the output to conform strictly to the grammar, so a generator has less freedom than a parser. Section 5.2 adds that generators should escape U+2028 and U+2029. The words serializer and stringify describe the same role.
H
Hexadecimal literal #
An integer written in base 16: 0x or 0X, then one or more hex digits in either case, with an optional sign in front. There are no hexadecimal fractions, and a parsed value keeps no memory that it was written in hex.
JSON5.parse('0xdecaf'); // 912559
JSON5.parse('-0XC0FFEE'); // -12648430
JSON5.stringify(JSON5.parse('0xFF')); // '255'Hjson #
Hjson is a separate JSON syntax extension aimed at people editing files by hand. It allows #, // and block comments, optional commas, unquoted object names, strings without quotes, and triple-quoted multiline strings. A JSON5 parser rejects hash comments, missing commas, strings without quotes and triple quotes. See the format family.
HOCON #
Human-Optimized Config Object Notation, from the Lightbend config project, which describes its document as an informal spec. It is a JSON superset with comments plus features JSON5 deliberately lacks, including substitutions that reference other values, file includes, and unquoted strings.
HuJSON #
"Human JSON", the name of Tailscale's Go package that implements JWCC: JSON plus line and block comments plus a trailing comma after the last member or element.
I
IdentifierName #
The ES5 production (section 7.6) that decides which object names may go without quotes. The first character is a Unicode letter (categories Lu, Ll, Lt, Lm, Lo or Nl), $, _, or a \uHHHH escape. Later characters may also be combining marks (Mn, Mc), decimal digits (Nd), connector punctuation (Pc), or the zero-width non-joiner and joiner. An IdentifierName is broader than an Identifier because it includes reserved words, so while is a legal unquoted name.
JSON5.parse('{ $a: 1, _b: 2, caf\\u00e9: 3, while: 4 }');
// { '$a': 1, _b: 2, 'café': 3, while: 4 }
JSON5.parse('{a-b: 1}'); // SyntaxError: invalid character '-' at 1:3
JSON5.parse('{1a: 1}'); // SyntaxError: invalid character '1' at 1:2Unquoted form is allowed for names only, never for string values. Names such as a-b need quotes. The reference library's unreleased main branch notes that moving from Unicode 10 to Unicode 18 data widens the set it accepts unquoted.
Infinity #
The IEEE 754 positive infinity, written exactly Infinity, optionally signed; -Infinity is negative infinity. JSON has no way to write it, and JSON.stringify turns it into null, so converting a document to JSON loses the value.
const d = JSON5.parse('{max: Infinity, min: -Infinity}');
JSON5.stringify(d); // '{max:Infinity,min:-Infinity}'
JSON.stringify(d); // '{"max":null,"min":null}'J
JSON #
JavaScript Object Notation, the strict data format defined by both RFC 8259 and ECMA-404. It has double-quoted strings and names, decimal numbers, true, false, null, objects and arrays, with no comments and no trailing commas.
JSON Schema #
A vocabulary for describing and validating JSON data, itself written as a document of the same data model. The project site lists 2020-12 as the current version. Because it validates parsed values rather than text, it applies to JSON5 documents once they are parsed. Walkthrough: schema validation.
JSON5 #
"The JSON5 Data Interchange Format", version 1.0.0, dated March 2018. A superset of JSON that adds syntax from ES5: unquoted names, single-quoted and continued strings, more escapes, more number forms, comments, trailing commas and extra white space. It adds no object, array or string types; Infinity and NaN do extend which number values can be written. Start with why it exists or the specification guide.
JSON5Text #
The goal symbol of the syntactic grammar, meaning one complete document: exactly one value, with white space and comments around it. The value may be a bare string, number, boolean or null; an object at the top level is not required. Two values in one text are an error.
JSONC #
JSON with Comments. The format was introduced informally by Microsoft for VS Code configuration files, and jsonc.org publishes a draft specification based on what the jsonc-parser library accepts by default. It adds line and block comments. Parsers may support trailing commas but are not required to. Unquoted names and single quotes are not part of it. The draft recommends the .jsonc extension and the media type application/jsonc. See the comparison.
JSONL and NDJSON #
Line-delimited JSON, one JSON value per line. JSON Lines requires UTF-8, a valid JSON value on every line and \n as the line terminator (one after the last value is recommended, not required). It names .jsonl as the file extension and notes that the media type application/jsonl is not yet standardized. The NDJSON specification (1.0.0) uses .ndjson and application/x-ndjson. Neither name has anything to do with JSON5, and a JSON5 parser rejects two documents in one string. Parsing each line separately works as long as no document or string spans lines.
const lines = '{id: 1}\n{id: 2}';
JSON5.parse(lines); // SyntaxError: invalid character '{' at 2:1
lines.split('\n').map((line) => JSON5.parse(line)); // [ { id: 1 }, { id: 2 } ]L
Leading and trailing decimal points #
A number may begin with the point (.5) or end with it (5.). JSON requires digits on both sides. A point with no digits at all is not a number.
JSON5.parse('.5'); // 0.5
JSON5.parse('5.'); // 5
JSON5.parse('.'); // SyntaxError: invalid end of input at 1:2Line comment #
The spec's "single line comment": it starts with // and runs to the next line terminator or the end of the document. Because U+2028 and U+2029 are line terminators, they end a line comment too. Inside a string, // is ordinary text. More in comment best practices.
{
// This whole line is ignored
url: 'https://example.com/', // so is this tail
}Line continuation #
A backslash immediately before a line terminator inside a string. Both the backslash and the terminator are dropped, so the string carries on. Indentation on the next line is part of the string. An unescaped LF or CR inside a string is a syntax error.
JSON5.parse("'a \\\n b'"); // 'a b' (the four spaces survive)
JSON5.parse("'a\nb'"); // SyntaxError: invalid character '\n' at 2:0Line separator and paragraph separator #
U+2028 (LINE SEPARATOR) and U+2029 (PARAGRAPH SEPARATOR). ES5 treats both as line terminators and so bans them unescaped in string literals. JSON allows them, and JSON5 follows JSON to remain a superset. The spec tells authors to avoid them, says parsers should warn, and says generators should escape them. ECMAScript 2019 adopted a proposal that allows them in JavaScript strings, which removed the mismatch. Version 2.2.3 of the reference library warns on the console and escapes them on output; its unreleased main branch removes the warning.
JSON5.parse("'a\u2028b'").length; // 3, and 2.2.3 logs a warning
JSON5.stringify('a\u2028b'); // "'a\\u2028b'"Line terminator #
One of four code points: U+000A line feed, U+000D carriage return, U+2028 and U+2029. For a line continuation, the pair CR LF counts as one sequence.
Lossless parser #
A parser that keeps comments, spacing, quote style and number spelling, so that a document can be edited and written back with only the intended change. The term is not from the spec, and JSON5.parse is not one. Examples include the model API of json-five for Python, which documents round-trip editing with comments preserved, and @croct/json5-parser for Node.js. See round-trip.
M
Media type (MIME type) #
The label, such as application/json, that identifies content in protocols like HTTP. application/json is registered for JSON through RFC 8259. The JSON5 spec names no media type, and the IANA registry had no entry for JSON5 when this page was reviewed. application/json5 is in informal use; a maintainer of the reference library approved it in issue 123 in 2017. The file extension is .json5. See the .json5 file and standards status.
Member and name #
A member is one name/value pair of an object. The name is either a string or an unquoted IdentifierName, a single colon separates it from the value, and a comma separates one member from the next. The spec describes an object as an unordered collection of members, although an implementation may let calling software see their order. See duplicate names.
N
NaN #
The IEEE 754 "not a number" value, written exactly NaN, optionally signed (the sign has no effect in JavaScript). It is not equal to itself, so test for it with Number.isNaN. Like Infinity, it becomes null in JSON output. A platform without NaN may reject it; a maintainer said as much in spec issue 24.
Number #
A decimal literal, a hexadecimal literal, Infinity or NaN, each with an optional sign. The grammar sets no size or precision limit; a parser may impose one. The reference library returns a JavaScript number, so a large integer can be rounded.
String(JSON5.parse('9007199254740993')); // '9007199254740992'P
Parse #
To turn text into data. In the reference library, JSON5.parse(text, reviver) returns a JavaScript value or throws a SyntaxError that carries lineNumber and columnNumber. See the JavaScript guide and the error reference.
Prototype pollution #
A JavaScript vulnerability in which untrusted keys such as __proto__ change what an object inherits. CVE-2022-46175 affected JSON5.parse up to and including 2.2.1 (and 1.x before 1.0.2); it altered the prototype of the returned object, not the global Object.prototype. Fixed releases are 2.2.2 and 1.0.2 or later. Details in the security guide.
const d = JSON5.parse('{"__proto__": {"admin": true}}'); // json5 2.2.3
d.admin; // undefined
Object.hasOwn(d, '__proto__'); // true: an ordinary own propertyPunctuator and token #
A token is one unit the lexical grammar produces: an identifier, a punctuator, a string or a number (with true, false and null as literal names). The six punctuators are { } [ ] : ,. White space and comments may appear before and after any token but are not tokens. The grammar page has the productions.
R
Reference implementation #
The json5 package on npm, from github.com/json5/json5, which its README describes as a reference implementation for parsing and serialization. The latest release on npm at this review was 2.2.3. The spec, not the library's API, decides what conforms. Others are listed under implementations.
Replacer #
The second argument of stringify. As a function, it receives each key and value before serialization and returns what to write. As an array, it is an allow list of property names applied at every depth.
JSON5.stringify({a: 1, b: 2, c: {a: 3, b: 4}}, ['a', 'c']);
// '{a:1,c:{a:3}}'Reviver #
The optional second argument of parse. It is called for every key and value after parsing, children before parents, ending with the root under the empty key. Whatever it returns replaces the value; returning undefined deletes the property.
JSON5.parse('{a:1,b:2}', (k, v) => (typeof v === 'number' ? v * 10 : v));
// { a: 10, b: 20 }RFC 8259 #
RFC 8259, "The JavaScript Object Notation (JSON) Data Interchange Format", is the IETF Standards Track document for JSON, published December 2017. It obsoletes RFC 7159. It adds interoperability advice that the bare syntax does not carry, such as that names within an object should be unique and that text exchanged between open systems must be UTF-8. No RFC defines JSON5.
Round-trip #
Parsing a document and serializing the result. A data round-trip keeps values; a source round-trip keeps the text. The reference library offers only the first: comments vanish, hex becomes decimal, and formatting is regenerated. Negative zero is also written as 0.
const v = JSON5.parse('{\n // keep me\n a: 0x10,\n}');
JSON5.stringify(v, null, 2);
// {
// a: 16,
// }
JSON5.stringify(-0); // '0'S
Schema #
A machine-readable description of the shape that data must have: types, required members, ranges. A parser checks syntax; a schema checks meaning. The usual choice here is JSON Schema. See validation tools.
Serializer #
Code that turns in-memory data into text, which the spec calls a generator. Serializer output can use any legal spelling. The reference library omits quotes on names that are IdentifierNames, picks whichever quote character needs less escaping for strings, and adds trailing commas when indentation is on.
Strict mode #
A restricted variant of ECMAScript introduced in ES5. It matters here in two ways: ES5 strict code forbids legacy octal literals such as 010, which JSON5 also rejects; and ES5 strict code made duplicate property names in an object literal an error, a rule that JSON5 does not apply. The phrase is not a JSON5 parsing mode: the spec defines none.
String #
Zero or more characters between matching single or double quotes. The enclosing quote, the backslash and line terminators must be escaped, with the exception of U+2028 and U+2029, which may appear as they are. See escape sequence and line continuation.
Stringify #
The reference library's serializer, JSON5.stringify(value, replacer, space), or JSON5.stringify(value, options) with replacer, space and quote. A numeric space is capped at 10; a string is cut to 10 characters. A toJSON5 method on a value takes priority over toJSON.
JSON5.stringify({a: [1, 'x']}, null, 2);
// {
// a: [
// 1,
// 'x',
// ],
// }
JSON5.stringify({ toJSON5() { return 'five'; }, toJSON() { return 'json'; } });
// "'five'"Superset and subset #
Format A is a superset of format B when every valid B text is also a valid A text. JSON5 is a superset of JSON. It is also described as a subset of ES5: its texts are valid ES5 expressions, with the one exception of unescaped U+2028 and U+2029 in strings, which ES2019 resolved. Valid syntax does not imply identical meaning, and evaluating a document with eval is unsafe.
Surrogate pair #
Two UTF-16 code units, one in the range D800 to DBFF and one in DC00 to DFFF, that together encode a code point above U+FFFF. Since \u escapes take exactly four hex digits, such a character is escaped as a pair. The grammar also admits an unpaired half; spec issue 12, still open, proposes recommending against it.
const s = JSON5.parse("'\\uD83C\\uDFBC'"); // U+1F3BC, a musical score
s.length; // 2 code units
[...s].length; // 1 code point
s.codePointAt(0).toString(16); // '1f3bc'
JSON5.parse("'\\uD800'").length; // 1: a lone surrogate is acceptedT
Trailing comma #
A single comma after the last member of an object or the last element of an array. One is legal; two are not, a comma alone inside empty brackets is not, and a comma before the first item is not. JSON forbids all of these. See trailing comma problems.
{ list: [1, 2,], } // valid
[1, 2,,] // invalid
[,] // invalid
{,} // invalidW
White space #
Characters that may surround any token and carry no meaning. JSON allows four (tab, line feed, carriage return, space). Section 8 of the spec lists more:
| Code point | Name | In JSON? |
|---|---|---|
| U+0009 | Horizontal tab | |
| U+000A | Line feed | |
| U+000B | Vertical tab | |
| U+000C | Form feed | |
| U+000D | Carriage return | |
| U+0020 | Space | |
| U+00A0 | Non-breaking space | |
| U+2028 | Line separator | |
| U+2029 | Paragraph separator | |
| U+FEFF | Byte order mark | |
| Category Zs | Any other Unicode space separator |
The zero width space, U+200B, is not in category Zs, and the reference parser rejects it between tokens. It is a classic invisible cause of parse errors.
Common Questions
What is the difference between a parser and a generator?
A parser reads text and must accept everything that matches the grammar, and may accept more. A generator writes text, and its output must match the grammar strictly.
Is every JSON file a JSON5 file?
Yes at the syntax level: JSON5 is a superset of JSON. The reverse is false, because comments, unquoted names, single quotes, trailing commas and the extra number forms are all invalid JSON.
Is JSONC the same thing as JSON5?
No. JSONC adds comments to JSON, and trailing commas are optional for its parsers. A JSON5 document that uses single quotes or unquoted names is not valid JSONC.
Can I use a reserved word such as class as an unquoted name?
Yes. Names follow IdentifierName, which includes reserved words. The same word is not valid as an unquoted string value.
Why does my value turn into null after converting to JSON?
JSON cannot represent Infinity or NaN, and JSON.stringify writes null for both. Check for them before converting.
Sources
(23)
- The JSON5 Data Interchange Format, version 1.0.0
- ECMAScript Language Specification, Edition 5.1
- RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format
- RFC 5234: Augmented BNF for Syntax Specifications
- ECMA-404: The JSON data interchange syntax
- json5 reference implementation: README
- json5 changelog, including unreleased changes
- json5-tests: parse test cases
- json5 issue 123: MIME type
- json5-spec issue 12: invalid surrogate pairs
- json5-spec issue 24: limits on NaN and Infinity
- IANA application media types registry (CSV)
- GitHub advisory GHSA-9c47-m6qq-7p4h (CVE-2022-46175)
- JSON Schema specification
- JSONC specification (draft)
- Nigel Tao: JSON With Commas and Comments
- tailscale/hujson README
- Hjson
- HOCON informal specification
- JSON Lines
- NDJSON specification
- json-five README
- @croct/json5-parser README
Last reviewed: November 29, 2026.
JavaScript
Python
TypeScript
Node.js
Rust
Java
C#
Ruby
Kotlin
Lua
Babel
Vite
webpack
ESLint
Prettier
VS Code
JetBrains