# json-bigint-patch

> JSON.parse with bigints support

Latest version **0.0.9** (published 2025-11-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install json-bigint-patch
pnpm add json-bigint-patch
yarn add json-bigint-patch
bun add json-bigint-patch
```

## Health

**Score 45/100 (D)** — status: stable.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.0.9 |
| Published | 2025-11-14 |
| First published | 2020-04-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 32.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 28 |
| Author | Arda TANRIKULU |
| Maintainers | ardatan |
| Keywords | JSON, bigint, bignumber, parse, json |

## Links

- npm: https://www.npmjs.com/package/json-bigint-patch
- Repository: git@github.com:ardatan/json-bigint-patch
- npm.io page: https://npm.io/package/json-bigint-patch

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.0.9 (latest) — 2025-11-14
- 0.0.8 — 2022-03-30
- 0.0.7 — 2022-03-30
- 0.0.6 — 2022-03-30
- 0.0.4 — 2020-04-21
- 0.0.3 — 2020-04-21
- 0.0.2 — 2020-04-05
- 0.0.1 — 2020-04-04

## README

json-bigint-patch
===========

[![NPM](https://nodei.co/npm/json-bigint-patch.png?downloads=true&stars=true)](https://nodei.co/npm/json-bigint-patch/)

JSON.parse/stringify with bigints support. Based on Douglas Crockford [JSON.js](https://github.com/douglascrockford/JSON-js) package and [BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) feature of JavaScript.

While most JSON parsers assume numeric values have same precision restrictions as IEEE 754 double, JSON specification _does not_ say anything about number precision. Any floating point number in decimal (optionally scientific) notation is valid JSON value. It's a good idea to serialize values which might fall out of IEEE 754 integer precision as strings in your JSON api, but `{ "value" : 9223372036854775807}`, for example, is still a valid RFC4627 JSON string, and in most JS runtimes the result of `JSON.parse` is this object: `{ value: 9223372036854776000 }`

==========

example:

```js

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

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

require('json-bigint-patch');

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

Output:

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

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


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

### Links:
- [RFC4627: The application/json Media Type for JavaScript Object Notation (JSON)](http://www.ietf.org/rfc/rfc4627.txt)
- [Re: \[Json\] Limitations on number size?](http://www.ietf.org/mail-archive/web/json/current/msg00297.html)
- [Is there any proper way to parse JSON with large numbers? (long, bigint, int64)](http://stackoverflow.com/questions/18755125/node-js-is-there-any-proper-way-to-parse-json-with-large-numbers-long-bigint)
- [What is JavaScript's Max Int? What's the highest Integer value a Number can go to without losing precision?](http://stackoverflow.com/questions/307179/what-is-javascripts-max-int-whats-the-highest-integer-value-a-number-can-go-t)
- [Large numbers erroneously rounded in Javascript](http://stackoverflow.com/questions/1379934/large-numbers-erroneously-rounded-in-javascript)

---
_Source: https://npm.io/package/json-bigint-patch · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
