@bybrave/json5

中文文档
3.1.0发布于 2026/07/05MITTypeScriptESM + CJS零依赖近 30 天下载 8881

Maintained fork of json5 — the JSON5 parser/stringifier with fixed dual ESM/CJS exports (named exports match, #240/#348), esbuild build, and bundled TypeScript types

原始使用文档
文档目录6 节
  1. What's fixed
  2. Modernized build
  3. Extras (opt-in)
  4. Migration from json5
  5. Support
  6. Credits & license

@bybrave/json5

Maintained, drop-in fork of json5 — the JSON5 (JSON for humans) parser and stringifier: comments, unquoted keys, trailing commas, single quotes, hex, and more.

The original has had no release since 2022 (2.2.3) while still pulling ~800M downloads/month. This fork keeps the parser 100% compatible and fixes the long-standing ESM packaging bug, modernizes the build, and bundles TypeScript types.

npm install @bybrave/json5
const JSON5 = require('@bybrave/json5');        // CommonJS
import JSON5 from '@bybrave/json5';              // ESM (default)
import { parse, stringify } from '@bybrave/json5'; // ESM (named) — now works

Same API as json5: JSON5.parse(text, reviver?) and JSON5.stringify(value, replacer?, space?).

What's fixed

IssueProblemFix
#240The ESM build (module field) exported only { default: {...} } while CJS exported { parse, stringify }. Bundlers that prefer module (webpack) broke on import { parse }, and import/require disagreed on shape.ESM-first sources with an exports map: import JSON5 from …, import { parse, stringify } from …, and require(…) all resolve to the same shape.
#348Request to ship real ES modules (tree-shaking, no CJS-interop shim).Sources are ES modules; the CJS entry is generated from them via the require condition.
#205Ask to drop the minimist CLI dependency.Already resolved upstream (CLI uses a hand-rolled arg parser); this fork ships zero runtime dependencies.

Modernized build

The original toolchain (rollup 0.64 + buble + core-js 2, 15 dev-dependencies) is replaced by a single esbuild step producing the CJS entry and a minified browser (UMD-style window.JSON5) bundle. Dev-dependencies drop to three (esbuild, typescript, @types/node). No runtime dependencies.

Targets Node 18+. The browser bundle targets ES2015 (the original ES5 legacy target is dropped — a deliberate choice for a 2026 major).

Extras (opt-in)

Large integers (bigint) — integer literals outside the safe range lose precision in JSON.parse/json5. Pass { bigint: true } to get them back as BigInt (#292); everything else is unchanged, and stringify serializes BigInt back to a bare literal:

JSON5.parse('12345678901234567890');                 // 12345678901234567000  (imprecise)
JSON5.parse('12345678901234567890', { bigint: true }); // 12345678901234567890n
JSON5.stringify(99999999999999999999n);               // '99999999999999999999'

Options may also be passed as the second argument: JSON5.parse(text, { bigint: true }).

Lone surrogates — stringify now escapes unpaired surrogate code units as \uXXXX instead of emitting an invalid string that reads back as U+FFFD (#192). Valid surrogate pairs (emoji, etc.) are untouched.

Migration from json5

Replace the dependency and the import — the parser and stringifier behave identically. The only change is packaging: import { parse, stringify } now works, and the import/require shapes match. If you consumed the deprecated json5/register require-hook, it moved to @bybrave/json5/register.

Support

If this package saves you time, you can support maintenance:

Ko-fi Bitcoin

Bitcoin (BTC): bc1q37557q5jpeaxqydzwvf3jgj7zhnfpn2td3q40q

Credits & license

MIT, same as the original — see LICENSE.md. Based on json5 by Aseem Kishore, Jordan Tucker and contributors.

版本与发布记录

@bybrave/json5 共发布 2 个版本,首次发布于 2026/07/05;过去 12 个月发布了 2 个版本。

版本发布日期距今
3.1.0latest2026/07/054 个月前
3.0.02026/07/054 个月前

关于 @bybrave/json5 的常见问题

@bybrave/json5 是什么?

Maintained fork of json5 — the JSON5 parser/stringifier with fixed dual ESM/CJS exports (named exports match, #240/#348), esbuild build, and bundled TypeScript types

如何安装 @bybrave/json5?

在项目目录运行 npm install @bybrave/json5,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 json5,可以用 npx json5 直接运行。

@bybrave/json5 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@bybrave/json5 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@bybrave/json5 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@bybrave/json5 可以商用吗?

@bybrave/json5 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@bybrave/json5 的下载量有多少?

根据 npm 官方下载统计,@bybrave/json5 在 2026/10/09 – 2026/11/07 这 30 天内被下载 8,881 次,日均约 296 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bybrave/json5 还在维护吗?

最新版本 3.1.0 发布于 2026/07/05(4 个月前);至今共发布 2 个版本,其中过去 12 个月发布了 2 个;首次发布于 2026/07/05。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。