JSON5 extends JSON with comments, unquoted keys, trailing commas, and relaxed strings for hand-edited config files. The npm package provides parse and stringify compatible with the JSON API.
Overview
JSON5 is a data interchange format that keeps valid JSON as valid JSON5 while adding ECMAScript 5.1-style conveniences for humans writing configuration by hand. It is explicitly not aimed at machine-to-machine protocols where plain JSON remains appropriate.
Syntax extensions include unquoted object keys, single-quoted and multiline strings, hexadecimal numbers, leading or trailing decimal points, explicit plus signs, NaN and infinities, trailing commas in objects and arrays, comments, and additional whitespace characters. Valid JSON5 files are also valid ES5 text, and the format has a published specification separate from this reference JavaScript implementation.
The JavaScript library exposes JSON5.parse and JSON5.stringify with options such as bigint parsing, customizable quoting, and spacing that preserves trailing commas when indenting. Node users can register a loader to require JSON5 files directly, and a global CLI converts JSON5 documents to strict JSON or validates syntax without emitting output.
Adopters mentioned in project materials include Chromium, Next.js, Babel, Retool, and WebStorm, and Apple platforms are said to support the format natively on macOS and iOS. TypeScript typings ship with the package, and browser UMD builds are documented for non-Node use.
Key features
- Comments in config files
- Unquoted and single-quoted keys
- Trailing commas in objects and arrays
- Hexadecimal and special numeric literals
- JSON-compatible parse and stringify API
- Node require hook for .json5 files
- CLI convert and validate commands
- Bundled TypeScript type declarations
Use cases
- Hand-maintained application config files
- Migrating human-edited JSON configs
- Tooling that accepts relaxed JSON syntax
- Validating JSON5 before strict JSON export
- Browser or Node JSON5 parsing