# @apimatic/json-bigint 中文文档

规范地址：https://npmcn.com/package/%40apimatic/json-bigint/

版本：1\.2\.0
npm 元数据更新时间：2026-07-09T04:03:45.598Z
中文译文更新时间：2026-11-06T10:10:02.492Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40apimatic/json-bigint
原文对照：https://npmcn.com/package/%40apimatic/json-bigint/?lang=original
项目主页：https://github.com/apimatic/json-bigint#readme
源码仓库：https://github.com/apimatic/json-bigint

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：37.6 kB，7 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- 运行依赖：0 个
- 首次发布：2021-09-01T09:22:26.134Z
- 最新版本发布：2022-03-14T11:15:28.052Z
- 近 30 天下载量：1446138（2026-10-06 至 2026-11-04，npm 官方下载统计）
- 已发布版本数：7（近 12 个月 0 个）

## 中文简介

JSON.parse 与大意支持

## 安装

```sh
npm install @apimatic/json-bigint
```

也可以使用：`pnpm add @apimatic/json-bigint`、`yarn add @apimatic/json-bigint`、`bun add @apimatic/json-bigint`

## README

# @apimatic/json-bigint (英语)

[![Build Status](https://github.com/apimatic/json-bigint/actions/workflows/main.yml/badge.svg)](https://github.com/apimatic/json-bigint/actions/main.yml)

JSON.parse/被大意支持. 根据道格拉斯克罗克福德 [JSON.js (英语)](https://github.com/douglascrockford/JSON-js) 软件包。 这是叉子 [json- bigint (日语)](https://github.com/sidorares/json-bigint)。本模块对大数.js没有支持,因此取消了该依赖性.

使用 npm 安装库 :

```
$ npm install @apimatic/json-bigint
```

虽然大多数JSON解析器假设数字值的精度限制与IEEE 754双倍相同,但JSON规格 _没有_ 说说数字精度 十进制中的任何浮点数(可选的科学)注音都是有效的JSON值. 将可能从IEEE 754整数精度中掉出作为JSON api中的字符串的数值序列化是一个好主意,但 `{ "value" : 9223372036854775807}`例如,仍然是一个有效的RFC4627 JSON字符串,在大多数JS运行时间中,结果是 `JSON.parse` 是该对象 : `{ value: 9223372036854776000 }`

\==========

示例:

```js
var JSONbig = require('@apimatic/json-bigint');

var json = '{ "value" : 9223372036854775807, "v2": 123 }';
console.log('Input:', json);
console.log('');

console.log('node.js built-in JSON:');
var r = JSON.parse(json);
console.log('JSON.parse(input).value : ', r.value.toString());
console.log('JSON.stringify(JSON.parse(input)):', JSON.stringify(r));

console.log('\n\nbigint JSON:');
var r1 = JSONbig.parse(json);
console.log('JSONbig.parse(input).value : ', r1.value.toString());
console.log('JSONbig.stringify(JSONbig.parse(input)):', JSONbig.stringify(r1));
```

输出 :

```
Input: { "value" : 9223372036854775807, "v2": 123 }

node.js built-in JSON:
JSON.parse(input).value :  9223372036854776000
JSON.stringify(JSON.parse(input)): {"value":9223372036854776000,"v2":123}


bigint JSON:
JSONbig.parse(input).value :  9223372036854775807
JSONbig.stringify(JSONbig.parse(input)): {"value":9223372036854775807,"v2":123}
```

### 选项

解析器的行为可以通过“ 选项” 来描述

#### 选项。 严格、布尔、默认假

指定解析应“限制”在解析字符串中报告重复键. 默认遵循标准json允许的,并类似JSON的行为. 解析,但将上一个值与上一个指定给重复键相覆盖.

设置选项。 严格 = 真实值会在这种重复键出事时发生故障,从而警告您可能丢失的信息.

示例:

```js
var JSONbig = require('@apimatic/json-bigint');
var JSONstrict = require('@apimatic/json-bigint')({ strict: true });

var dupkeys = '{ "dupkey": "value 1", "dupkey": "value 2"}';
console.log('\n\nDuplicate Key test with both lenient and strict JSON parsing');
console.log('Input:', dupkeys);
var works = JSONbig.parse(dupkeys);
console.log('JSON.parse(dupkeys).dupkey: %s', works.dupkey);
var fails = 'will stay like this';
try {
  fails = JSONstrict.parse(dupkeys);
  console.log('ERROR!! Should never get here');
} catch (e) {
  console.log(
    'Succesfully catched expected exception on duplicate keys: %j',
    e
  );
}
```

产出

```
Duplicate Key test with big number JSON
Input: { "dupkey": "value 1", "dupkey": "value 2"}
JSON.parse(dupkeys).dupkey: value 2
Succesfully catched expected exception on duplicate keys: {"name":"SyntaxError","message":"Duplicate key \"dupkey\"","at":33,"text":"{ \"dupkey\": \"value 1\", \"dupkey\": \"value 2\"}"}

```

#### 选项.storeAsString,布尔,默认虚假

指定是否将 BigInts 作为字符串存储在对象中.

注意,这是一个危险的行为,因为它打破了能够不改变数据类型而转换回转和forth的默认功能(因为这会将所有的 BigInts 转换为活塞字符串).

示例:

```js
var JSONbig = require('@apimatic/json-bigintt');
var JSONbigString = require('@apimatic/json-bigint')({ storeAsString: true });
var key = '{ "key": 1234567890123456789 }';
console.log('\n\nStoring the BigInt as a string, instead of a BigInt');
console.log('Input:', key);
var withInt = JSONbig.parse(key);
var withString = JSONbigString.parse(key);
console.log(
  'Default type: %s, With option type: %s',
  typeof withInt.key,
  typeof withString.key
);
```

产出

```
Storing the BigInt as a string, instead of a BigInt
Input: { "key": 1234567890123456789 }
Default type: bigint, With option type: string

```

#### 选项。总是ParseAsBig,布尔,默认的虚假

指定是否将所有数字存储为 BigInt .

注意,这是一个危险的行为,因为它打破了无需数据类型变化即可转换回转和forth的默认功能(因为这会将所有数字转换为-和- stayy BigInt)

示例:

```js
var JSONbig = require('@apimatic/json-bigint');
var JSONbigAlways = require('@apimatic/json-bigint')({ alwaysParseAsBig: true });
var key = '{ "key": 123 }'; // there is no need for BigInt by default, but we're forcing it
console.log(`\n\nStoring the Number as a BigInt, instead of a Number`);
console.log('Input:', key);
var normal = JSONbig.parse(key);
var always = JSONbigAlways.parse(key);
console.log(
  'Default type: %s, With option type: %s',
  typeof normal.key,
  typeof always.key
);
```

产出

```
Storing the Number as a BigInt, instead of a Number
Input: { "key": 123 }
Default type: number, With option type: bigint

```

#### 选项. proto Action, boolean, 默认: “ 错误”。 可能的值:"error","ingrore","保有"

#### 选项. 构建器动作,布尔,默认:"error". 可能的值:"error","ingrore","保有"

如何控制 `__proto__` 财务报告和审定财务报表 `constructor` 属性被处理。 如果设定为“ 错误” , 则不允许 和 解析() 调用会丢出一个错误 。 如果设置为“ 忽略” 棱镜和它; 数值会从剖析和对象建筑中跳出 . 如果设置为“ 保存 ” `__proto__` 属性设置。 一个人应该格外小心,并确保任何其他消耗生成的数据的图书馆 不易被原型中毒攻击.

示例:

```js
var JSONbigAlways = require('@apimatic/json-bigint')({ protoAction: 'ignore' });
const user = JSONbig.parse('{ "__proto__": { "admin": true }, "id": 12345 }');
// => result is { id: 12345 }
```

### 链接 :

-   [RFC4627:JavaScript对象标记(JSON)的应用程序/json介质类型](http://www.ietf.org/rfc/rfc4627.txt)
-   [Re:\[Json\] 数字大小的限制?](http://www.ietf.org/mail-archive/web/json/current/msg00297.html)
-   [有没有适当的方法来分析 JSON 大量? (长相相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相相接相接相接相接相接相接相接相相相接相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相](http://stackoverflow.com/questions/18755125/node-js-is-there-any-proper-way-to-parse-json-with-large-numbers-long-bigint)
-   [JavaScript的"麦克斯"是什么? Number在不失去精确度的情况下能达到的最高整数值是什么?](http://stackoverflow.com/questions/307179/what-is-javascripts-max-int-whats-the-highest-integer-value-a-number-can-go-t)
-   [大量数字在 Javascript 中误入四舍五入](http://stackoverflow.com/questions/1379934/large-numbers-erroneously-rounded-in-javascript)

### 关于本地 BigInt 支持的说明

#### 字符串

完全支持出框,将 BigInts 字符串为纯数字( 无引号, 否) `n`(中文(简体) )

#### 限制

-   往返业务

`s === JSONbig.stringify(JSONbig.parse(s))` 不过

`o !== JSONbig.parse(JSONbig.stringify(o))`

何时 `o` 有价值的东西 `123n`。 。 。 .

`JSONbig` 字符串 `123n` 作为 `123`,变成 `number` (亚卡语) `123` 没有 `123n`)在被修复时默认存在.

目前没有一致的方法来处理这个问题,所以我们决定离开它,然后由用户来处理这个具体案件.

## 常见问题

### @apimatic/json-bigint 是什么？

JSON\.parse 与大意支持

### 如何安装 @apimatic/json-bigint？

在项目目录运行 npm install @apimatic/json-bigint，或使用 pnpm add / yarn add / bun add。

### @apimatic/json-bigint 支持 TypeScript 吗？

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

### @apimatic/json-bigint 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @apimatic/json-bigint 可以商用吗？

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

### @apimatic/json-bigint 的下载量有多少？

根据 npm 官方下载统计，@apimatic/json-bigint 在 2026/10/06 – 2026/11/04 这 30 天内被下载 1,446,138 次，日均约 48,205 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @apimatic/json-bigint 还在维护吗？

最新版本 1\.2\.0 发布于 2022/03/14（4 年前）；至今共发布 7 个版本，其中过去 12 个月发布了 0 个；首次发布于 2021/09/01。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

