Repository navigation
Breaking release!.. ESM-only, Node.js 22+, and a few behavior changes; see Changed. The method names and signatures are the same as v2.
Added
allowTrailingCommasoption forparse(),read(),readSync()and their safe versions. Opt-in (defaultfalse); allows trailing commas in objects and arrays, as in JSONC files such astsconfig.json. Takes effect only when comments are stripped.- Generic return types for
parse<T>(),read<T>(),readSync<T>()andnormalize<T>()(defaultany); the safe versions returnSafeResult<T>. The type is not validated at runtime. handleCircularoption forwrite()/writeSync()(defaulttrue).- Named exports:
jsonc,safeand all option types (IParseOptions,IStringifyOptions,IReadOptions,IWriteOptions,IConfig,Replacer,Reviver,SafeResult);jsoncis also the default export. In v2, the typings only declaredjsonc, soimport { safe } from 'jsonc'did not type-check.
Changed
- Breaking: ESM-only. The package is now
"type": "module"with anexportsmap; the CommonJSindex.jsentry is removed. On Node.js 22.12 or newer,require('jsonc')still works (Node'srequire(esm)) and returnsjsoncitself as in v2; soconst jsonc = require('jsonc')andconst { jsonc, safe } = require('jsonc')both work. On 22.0 – 22.11, useimport. - Breaking: Requires Node.js 22 or newer (was 8).
- Breaking:
write()/writeSync()now handle circular references likestringify()does (written as"[Circular]"); they used to throw. PasshandleCircular: falsefor the old behavior. - Breaking:
stringify()(andnormalize()) now throw for aBigIntand rethrow any other serialization error (e.g. from atoJSON()), as the native method does. They used to return the string"[unable to serialize, circular reference is too complex to analyze]". - Breaking:
safe.stringify()now honorshandleCircular: falseand returns[TypeError, undefined]for a circular value; it used to ignore the option. parse()now replaces comments with whitespace instead of removing them, so the position, line and column in a parse error point into the original string (read()already did this). The parsed result is the same.write()/writeSync()return type is narrowed frombooleantotrue.config()argument is now optional; omitted streams reset toprocess.stdout/process.stderr.- Updated
parse-jsonto v8 andstrip-json-commentsto v5. Parse errors areparse-jsonv8'sJSONError(with a code frame).
Fixed
- Fixed an issue where
log()/logp()would print an empty string forundefinedand would throw for aSymbolargument. - Fixed the
Replacertype, which only allowed a function; it now also accepts an allow-list array of property names (as the runtime always did). - Fixed the
IConfigstream types (NodeJS.WriteStream, i.e. a TTY stream), which rejected file streams such asfs.createWriteStream(). They are nowNodeJS.WritableStream. - Fixed broken examples in the API docs (safe
read()/write()examples had syntax errors;stringify()docs claimed it throws on circular references by default).
Removed
- Removed the
graceful-fs,mkdirpandstrip-bomdependencies; file I/O usesnode:fsandnode:fs/promises, with native recursivemkdir. Runtime dependencies are nowfast-safe-stringify,parse-jsonandstrip-json-comments. - Removed the Docma docs build; the README is the documentation now.
Tooling
- TypeScript build (
tsc) tolib/withtsconfig-oy; Biome (biome-config-oy) replaces TSLint. - Vitest replaces Jest; 100% coverage on all four metrics plus Stryker mutation testing at 100%.
- GitHub Actions CI (Node.js 22, 24, 26 + a mutation job) replaces Travis CI and Coveralls.