JSON6 JSON6 Cheat Sheet

A one-page reference for all JSON6 syntax and the json-6 API. Print it, bookmark it, or keep it handy.

Click to open the print dialog, then save as PDF

Comments

// line comment /* block comment */ { a: 1 } // inline

Commas

{ a: 1, b: 2, } // trailing OK [1, 2, 3,] // trailing OK [1,, 3] // hole at 1 { a:1,, b:2 } // ERROR

Keys

{ bare: 1, x-api-key: 2, // hyphen OK 'single': 3, "double": 4, `tick`: 5, 42: 6, // key "42" }

Strings

"double" 'single' `tick` 'two lines' // newline kept 'one \ line' // newline removed `${x}` // literal text

Escapes

\n \r \t \b \f \v \0 \xNN 2 hex digits \uNNNN 4 hex digits \u{H...} code point \' \" \` \\ \q -> q (unknown)

Number bases

255 0xFF 0xff 0b1111_1111 binary 0o377 octal 0123 = 123 (decimal!) 1_000_000 separators

Decimals and signs

.5 5. 1e3 1.5E-2 +10 -10 ---10 // = -10 Infinity -Infinity NaN

Keywords

true false null undefined // JSON6 only { while: true } // keywords are fine as keys

Whitespace

space tab CR LF NBSP VT FF U+2028 U+2029 // all allowed between // tokens

Install and parse

npm install json-6 const JSON6 = require('json-6') JSON6.parse(text, reviver, options)

Stringify

JSON6.stringify(v, replacer, space, { sortKeys: false }) // keys sorted by default // bare keys when possible JSON6.escape(str)

Parse options

esStrictCompatible forbidTemplateSubstitution normalizeNumericKeys warnWithCommentWithoutEOL // all default to false

Streaming

const p = JSON6.begin(cb) p.write(chunk) p.value() p.reset([options]) JSON6.stringifier()

Node.js

require('json-6/lib/require') node --import \ json-6/lib/register.mjs app.mjs // Node 20.6+ npx json-6 -c file.json6

Gotchas

parse('{a:1} x') -> {a:1} parse('') throws parse('[1 2]') throws Date -> {} in stringify BigInt not supported File extension: .json6

JSON6 is a proposed extension to JSON and not an official successor. Facts verified against json-6 1.1.7. Full detail at the syntax reference.

Using the cheat sheet

The entries on the sheet were checked against the json-6 1.1.7 README and by running that parser. The grid prints as a single page: use the button above, then choose "Save as PDF" in your browser's print dialog. The sheet assumes the parser's default options; with esStrictCompatible turned on, leading-zero numbers, repeated signs, back-tick keys, raw line breaks in ' and " strings and non-identifier unquoted keys are rejected.

Two entries deserve a second look. parse('{a:1} x') returns { a: 1 } because the parser stops after the first complete value and does not complain about what follows. And a Date value serializes as an empty object because stringify does not call toJSON; convert dates to ISO strings yourself first.

Learn JSON6 Step by Step

Follow the tutorials from first parse to production config files.