# JSON5 Glossary: Terms Defined From A to Z | JSON5.dev


Source: https://json5.dev/glossary/

---

# JSON5 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.

![An open reference book of JSON5 terms with alphabet tabs and labeled index cards under a warm desk lamp](https://json5.dev/img/hero/glossary.png)

**TL;DR:** JSON5 is a superset of JSON borrowing syntax from ECMAScript 5.1. The terms people mix up most are [JSONC](#jsonc) (comments only, trailing commas optional), [JWCC](#jwcc) (comments and trailing commas), [JSONL](#jsonl) (one JSON value per line, unrelated to JSON5), and [round-trip](#round-trip) (the reference library keeps data, not comments).

[All Terms](#index) [A](#letter-a) [B](#letter-b) [C](#letter-c) [D](#letter-d) [E](#letter-e) [G](#letter-g) [H](#letter-h) [I](#letter-i) [J](#letter-j) [L](#letter-l) [M](#letter-m) [N](#letter-n) [P](#letter-p) [R](#letter-r) [S](#letter-s) [T](#letter-t) [W](#letter-w) [FAQ](#faq) [Sources](#references)

![List icon](https://json5.dev/images/icons/list.png)

## 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.

[ABNF](#abnf)[Array](#array)[Block comment](#block-comment)[Byte order mark (BOM)](#byte-order-mark)[Code point](#code-point)[Conforming parser](#conforming-parser)[Duplicate names](#duplicate-names)[ECMA-404](#ecma-404)[ECMAScript](#ecmascript)[Escape sequence](#escape-sequence)[Explicit plus sign](#explicit-plus-sign)[Generator](#generator)[Hexadecimal literal](#hexadecimal-literal)[Hjson](#hjson)[HOCON](#hocon)[HuJSON](#hujson)[IdentifierName](#identifiername)[Infinity](#infinity)[JSON](#json)[JSON Schema](#json-schema)[JSON5](#json5)[JSON5Text](#json5text)[JSONC](#jsonc)[JSONL and NDJSON](#jsonl)[JWCC](#jwcc)[Leading and trailing decimal points](#leading-decimal-point)[Line comment](#line-comment)[Line continuation](#line-continuation)[Line separator and paragraph separator](#line-separator)[Line terminator](#line-terminator)[Lossless parser](#lossless-parser)[Media type (MIME type)](#media-type)[Member and name](#member)[NaN](#nan)[Number](#number)[Parse](#parse)[Prototype pollution](#prototype-pollution)[Punctuator and token](#punctuator)[Reference implementation](#reference-implementation)[Replacer](#replacer)[Reviver](#reviver)[RFC 8259](#rfc-8259)[Round-trip](#round-trip)[Schema](#schema)[Serializer](#serializer)[Strict mode](#strict-mode)[String](#string)[Stringify](#stringify)[Superset and subset](#superset)[Surrogate pair](#surrogate-pair)[Trailing comma](#trailing-comma)[White space](#white-space)

Definitions follow the [JSON5 1.0.0 specification](https://spec.json5.org/) 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](#identifiername)

Why a document fails to parse

[White space](#white-space), [line continuation](#line-continuation), [trailing comma](#trailing-comma)

Numbers JSON cannot write

[Hexadecimal literal](#hexadecimal-literal), [Infinity](#infinity), [NaN](#nan), [decimal points](#leading-decimal-point)

Writing files back

[Round-trip](#round-trip), [lossless parser](#lossless-parser), [stringify](#stringify)

Sibling formats

[JSONC](#jsonc), [JWCC](#jwcc), [Hjson](#hjson), [HOCON](#hocon), [JSONL](#jsonl)

![Letter A section icon](https://json5.dev/images/icons/book.png)

## A

### ABNF [#](#abnf)

Augmented Backus-Naur Form, a notation for writing grammars, specified in [RFC 5234](https://www.rfc-editor.org/rfc/rfc5234) (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 [#](#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.

![Letter B section icon](https://json5.dev/images/icons/comment.png)

## B

### Block comment [#](#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) [#](#byte-order-mark)

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](https://json5.dev/troubleshooting/encoding/).

![Letter C section icon](https://json5.dev/images/icons/checklist.png)

## C

### Code point [#](#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](#surrogate-pair): one code point above U+FFFF occupies two code units in a JavaScript string.

### Conforming parser [#](#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](https://github.com/json5/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.

![Letter D section icon](https://json5.dev/images/icons/warning.png)

## D

### Duplicate names [#](#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 }`

![Letter E section icon](https://json5.dev/images/icons/code.png)

## E

### ECMA-404 [#](#ecma-404)

[ECMA-404](https://ecma-international.org/publications-and-standards/standards/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 [#](#ecmascript)

The standardized language that JavaScript implements, published as ECMA-262. JSON5 borrows from one fixed edition, [ECMAScript 5.1](https://262.ecma-international.org/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](https://json5.dev/spec/ecmascript/) and [the features left out](https://json5.dev/design-rationale/).

### Escape sequence [#](#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

![No](https://json5.dev/images/icons/no.png)

`\"` `\\` `\/`

Quotation mark, reverse solidus, solidus

![Yes](https://json5.dev/images/icons/yes.png)

`\b` `\f` `\n` `\r` `\t`

Backspace, form feed, line feed, carriage return, tab

![Yes](https://json5.dev/images/icons/yes.png)

`\v`

Vertical tab, U+000B

![No](https://json5.dev/images/icons/no.png)

`\0`

Null, U+0000; a decimal digit must not follow

![No](https://json5.dev/images/icons/no.png)

`\xHH`

Exactly two hex digits, U+0000 through U+00FF

![No](https://json5.dev/images/icons/no.png)

`\uHHHH`

Exactly four hex digits, one UTF-16 code unit

![Yes](https://json5.dev/images/icons/yes.png)

Backslash before any other character

The character itself, except digits 1 through 9

![No](https://json5.dev/images/icons/no.png)

`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:4`

### Explicit plus sign [#](#explicit-plus-sign)

A number may start with `+` as well as `-`. This applies to decimal numbers, [hexadecimal literals](#hexadecimal-literal), [Infinity](#infinity) and [NaN](#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:2`

![Letter G section icon](https://json5.dev/images/icons/settings.png)

## G

### Generator [#](#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](#serializer) and [stringify](#stringify) describe the same role.

![Letter H section icon](https://json5.dev/images/icons/hashtag.png)

## H

### Hexadecimal literal [#](#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)

[Hjson](https://hjson.github.io/) 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](https://json5.dev/family/).

### HOCON [#](#hocon)

Human-Optimized Config Object Notation, from the [Lightbend config project](https://github.com/lightbend/config/blob/main/HOCON.md), 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 [#](#hujson)

"Human JSON", the name of [Tailscale's Go package](https://github.com/tailscale/hujson) that implements [JWCC](#jwcc): JSON plus line and block comments plus a trailing comma after the last member or element.

![Letter I section icon](https://json5.dev/images/icons/key.png)

## I

### IdentifierName [#](#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:2`

Unquoted 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 [#](#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}'`

![Letter J section icon](https://json5.dev/images/icons/document.png)

## J

### JSON [#](#json)

JavaScript Object Notation, the strict data format defined by both [RFC 8259](#rfc-8259) and [ECMA-404](#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 [#](#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](https://json-schema.org/specification) as the current version. Because it validates parsed values rather than text, it applies to JSON5 documents once they are parsed. Walkthrough: [schema validation](https://json5.dev/tutorials/schema-validation/).

### JSON5 [#](#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](https://json5.dev/why/) or the [specification guide](https://json5.dev/spec/).

### JSON5Text [#](#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 [#](#jsonc)

JSON with Comments. The format was introduced informally by Microsoft for VS Code configuration files, and [jsonc.org](https://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](https://json5.dev/compare/).

### JSONL and NDJSON [#](#jsonl)

Line-delimited JSON, one JSON value per line. [JSON Lines](https://jsonlines.org/) 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](https://github.com/ndjson/ndjson-spec) (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 } ]`

### JWCC [#](#jwcc)

"JSON With Commas and Comments", a name proposed by [Nigel Tao](https://nigeltao.github.io/blog/2021/json-with-commas-comments.html) in 2021 for a minimal extension: an optional comma after the final element or member, and C and C++ style comments. All JSON is valid JWCC. Each of its two additions also exists in JSON5, which then goes further.

![Letter L section icon](https://json5.dev/images/icons/text-format.png)

## L

### Leading and trailing decimal points [#](#leading-decimal-point)

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:2`

### Line comment [#](#line-comment)

The spec's "single line comment": it starts with `//` and runs to the next [line terminator](#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](https://json5.dev/tutorials/comments-best-practices/).

`{ // This whole line is ignored url: 'https://example.com/', // so is this tail }`

### Line continuation [#](#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:0`

### Line separator and paragraph separator [#](#line-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 [#](#line-terminator)

One of four code points: U+000A line feed, U+000D carriage return, U+2028 and U+2029. For a [line continuation](#line-continuation), the pair CR LF counts as one sequence.

### Lossless parser [#](#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](https://github.com/spyoungtech/json-five) for Python, which documents round-trip editing with comments preserved, and [@croct/json5-parser](https://github.com/croct-tech/json5-parser-js) for Node.js. See [round-trip](#round-trip).

![Letter M section icon](https://json5.dev/images/icons/globe.png)

## M

### Media type (MIME type) [#](#media-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](https://www.iana.org/assignments/media-types/application.csv) 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](https://github.com/json5/json5/issues/123) in 2017. The file extension is `.json5`. See [the .json5 file](https://json5.dev/json5-file/) and [standards status](https://json5.dev/standards/).

### Member and name [#](#member)

A member is one name/value pair of an object. The name is either a string or an unquoted [IdentifierName](#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](#duplicate-names).

![Letter N section icon](https://json5.dev/images/icons/infinity.png)

## N

### NaN [#](#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](#infinity), it becomes `null` in JSON output. A platform without NaN may reject it; a maintainer said as much in [spec issue 24](https://github.com/json5/json5-spec/issues/24).

### Number [#](#number)

A decimal literal, a [hexadecimal literal](#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'`

![Letter P section icon](https://json5.dev/images/icons/search.png)

## P

### Parse [#](#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](https://json5.dev/javascript/) and the [error reference](https://json5.dev/errors/).

### Prototype pollution [#](#prototype-pollution)

A JavaScript vulnerability in which untrusted keys such as `__proto__` change what an object inherits. [CVE-2022-46175](https://github.com/advisories/GHSA-9c47-m6qq-7p4h) 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](https://json5.dev/tutorials/security/).

`const d = JSON5.parse('{"__proto__": {"admin": true}}'); // json5 2.2.3 d.admin; // undefined Object.hasOwn(d, '__proto__'); // true: an ordinary own property`

### Punctuator and token [#](#punctuator)

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](https://json5.dev/spec/grammar/) has the productions.

![Letter R section icon](https://json5.dev/images/icons/refresh.png)

## R

### Reference implementation [#](#reference-implementation)

The `json5` package on npm, from [github.com/json5/json5](https://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](https://json5.dev/implementations/).

### Replacer [#](#replacer)

The second argument of [stringify](#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 [#](#reviver)

The optional second argument of [parse](#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)

[RFC 8259](https://www.rfc-editor.org/rfc/rfc8259), "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 [#](#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'`

![Letter S section icon](https://json5.dev/images/icons/structure.png)

## S

### Schema [#](#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](#json-schema). See [validation tools](https://json5.dev/tools/validation/).

### Serializer [#](#serializer)

Code that turns in-memory data into text, which the spec calls a [generator](#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 [#](#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 [#](#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](#escape-sequence) and [line continuation](#line-continuation).

### Stringify [#](#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 [#](#superset)

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](#line-separator) in strings, which ES2019 resolved. Valid syntax does not imply identical meaning, and evaluating a document with `eval` is unsafe.

### Surrogate pair [#](#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](https://github.com/json5/json5-spec/issues/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 accepted`

![Letter T section icon](https://json5.dev/images/icons/edit.png)

## T

### Trailing comma [#](#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](https://json5.dev/troubleshooting/trailing-commas/).

`{ list: [1, 2,], } // valid [1, 2,,] // invalid [,] // invalid {,} // invalid`

![Letter W section icon](https://json5.dev/images/icons/hidden.png)

## W

### White space [#](#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

![Yes](https://json5.dev/images/icons/yes.png)

U+000A

Line feed

![Yes](https://json5.dev/images/icons/yes.png)

U+000B

Vertical tab

![No](https://json5.dev/images/icons/no.png)

U+000C

Form feed

![No](https://json5.dev/images/icons/no.png)

U+000D

Carriage return

![Yes](https://json5.dev/images/icons/yes.png)

U+0020

Space

![Yes](https://json5.dev/images/icons/yes.png)

U+00A0

Non-breaking space

![No](https://json5.dev/images/icons/no.png)

U+2028

Line separator

![No](https://json5.dev/images/icons/no.png)

U+2029

Paragraph separator

![No](https://json5.dev/images/icons/no.png)

U+FEFF

Byte order mark

![No](https://json5.dev/images/icons/no.png)

Category Zs

Any other Unicode space separator

![No](https://json5.dev/images/icons/no.png)

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](https://json5.dev/troubleshooting/parse-errors/).

![Question icon](https://json5.dev/images/icons/question.png)

## 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.

## Related Pages

[

![Specification icon](https://json5.dev/images/icons/spec.png)

### Syntax Reference

Every syntax feature with examples.

](https://json5.dev/spec/syntax/)[

![Structure icon](https://json5.dev/images/icons/structure.png)

### Formal Grammar

The productions behind these definitions.

](https://json5.dev/spec/grammar/)[

![Idea icon](https://json5.dev/images/icons/idea.png)

### Design Rationale

What the format leaves out, and why.

](https://json5.dev/design-rationale/)[

![Branch icon](https://json5.dev/images/icons/branch.png)

### Format Family

How the related formats fit together.

](https://json5.dev/family/)[

![Checklist icon](https://json5.dev/images/icons/checklist.png)

### Cheat Sheet

The syntax on one page.

](https://json5.dev/cheatsheet/)

## Sources

(23)

1.  [The JSON5 Data Interchange Format, version 1.0.0](https://spec.json5.org/)
2.  [ECMAScript Language Specification, Edition 5.1](https://262.ecma-international.org/5.1/)
3.  [RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format](https://www.rfc-editor.org/rfc/rfc8259)
4.  [RFC 5234: Augmented BNF for Syntax Specifications](https://www.rfc-editor.org/rfc/rfc5234)
5.  [ECMA-404: The JSON data interchange syntax](https://ecma-international.org/publications-and-standards/standards/ecma-404/)
6.  [json5 reference implementation: README](https://github.com/json5/json5)
7.  [json5 changelog, including unreleased changes](https://github.com/json5/json5/blob/main/CHANGELOG.md)
8.  [json5-tests: parse test cases](https://github.com/json5/json5-tests)
9.  [json5 issue 123: MIME type](https://github.com/json5/json5/issues/123)
10.  [json5-spec issue 12: invalid surrogate pairs](https://github.com/json5/json5-spec/issues/12)
11.  [json5-spec issue 24: limits on NaN and Infinity](https://github.com/json5/json5-spec/issues/24)
12.  [IANA application media types registry (CSV)](https://www.iana.org/assignments/media-types/application.csv)
13.  [GitHub advisory GHSA-9c47-m6qq-7p4h (CVE-2022-46175)](https://github.com/advisories/GHSA-9c47-m6qq-7p4h)
14.  [JSON Schema specification](https://json-schema.org/specification)
15.  [JSONC specification (draft)](https://jsonc.org/)
16.  [Nigel Tao: JSON With Commas and Comments](https://nigeltao.github.io/blog/2021/json-with-commas-comments.html)
17.  [tailscale/hujson README](https://github.com/tailscale/hujson)
18.  [Hjson](https://hjson.github.io/)
19.  [HOCON informal specification](https://github.com/lightbend/config/blob/main/HOCON.md)
20.  [JSON Lines](https://jsonlines.org/)
21.  [NDJSON specification](https://github.com/ndjson/ndjson-spec)
22.  [json-five README](https://github.com/spyoungtech/json-five)
23.  [@croct/json5-parser README](https://github.com/croct-tech/json5-parser-js)

Last reviewed: November 29, 2026.
