Not with built-in JSON.parse. You'll need to parse it manually and treat values as string (if you want to do arithmetics with them there is bignumber.js) You can use Douglas Crockford JSON.js library as a base for your parser.

EDIT2 ( 7 years after original answer ) - it might soon be possible to solve this using standard JSON api. Have a look at this TC39 proposal to add access to source string to a reviver function - https://github.com/tc39/proposal-json-parse-with-source

EDIT1: I created a package for you :)

var JSONbig = require('json-bigint');

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

console.log('node.js bult-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\nbig number JSON:');
var r1 = JSONbig.parse(json);
console.log('JSON.parse(input).value : ', r1.value.toString());
console.log('JSON.stringify(JSON.parse(input)):', JSONbig.stringify(r1));

Output:

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

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


big number JSON:
JSON.parse(input).value :  9223372036854775807
JSON.stringify(JSON.parse(input)): {"value":9223372036854775807,"v2":123}
Answer from Andrey Sidorov on Stack Overflow
🌐
npm
npmjs.com › package › json-bigint
json-bigint - npm
July 14, 2020 - JSON.parse/stringify with bigints support.
      » npm install json-bigint
    
Published   Jul 14, 2020
Version   1.0.0
Author   Andrey Sidorov
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › BigInt
BigInt - JavaScript - MDN Web Docs
As a very generic example, an attacker ... regarding the issue. Using JSON.stringify() with any BigInt value will raise a TypeError, as BigInt values aren't serialized in JSON by default....
Discussions

TypeError: Do not know how to serialize a BigInt at JSON.stringify (<anonymous>)
The easiest way is to add a polyfill to augment the behaviour. Some people will say this is "prototype pollution", but this is the simplest way to "tell" JSON.stringify to serialize a BigInt: BigInt.prototype['toJSON'] = function () { return this.toString() } I add this to a "polyfills.ts" file in my app source root and import into the entrypoint file of the application. Note that you can also use BigInt.prototype.toJSON = function() {} but this makes Typescript complain that the property toJSON doesn't exist on the object, which of course, it doesn't. More on reddit.com
🌐 r/nextjs
11
2
December 5, 2023
node.js - Is there any proper way to parse JSON with large numbers? (long, bigint, int64)
After searching something more clean - and finding only libs like jsonbigint, I just wrote my own solution. Is not the best, but it solves my problem. For those that are using Axios you can use it on transformResponse callback (this was my original problem - Axios parses the JSON and all bigInts ... More on stackoverflow.com
🌐 stackoverflow.com
How to make JSON.parse() to treat all the Numbers as BigInt?
What if some numbers in that "bar" array would be small enough to also fit the "number" type, would you then want those numbers to still be bigints or not? Why? ... Save this answer. Show activity on this post. ... To control JSON.parse() behavior that way, you can make use of the second parameter ... More on stackoverflow.com
🌐 stackoverflow.com
typescript - Serialize BigInt in JSON - Stack Overflow
I'm looking for a way to force JSON.stringify to always print BigInts without complaining. I know it's non-standard, I know there's a package for that in pure JavaScript; but it doesn't fit my need... More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitHub
github.com › sidorares › json-bigint
GitHub - sidorares/json-bigint: JSON.parse/stringify with bigints support · GitHub
Storing the Number as native BigInt, instead of a BigNumber Input: { "key": 993143214321423154315154321 } Default type: object, With option type: bigint · Specifies if all numbers should be stored as BigNumber. Note that this is a dangerous behavior as it breaks the default functionality of being able to convert back-and-forth without data type changes (as this will convert all Number to be-and-stay BigNumber) ... var JSONbig = require('json-bigint'); var JSONbigAlways = require('json-bigint')({ alwaysParseAsBig: true }); var key = '{ "key": 123 }'; // there is no need for BigNumber by default, but we're forcing it console.log(`\n\nStoring the Number as a BigNumber, 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 );
Starred by 876 users
Forked by 203 users
Languages   JavaScript
🌐
Reddit
reddit.com › r/nextjs › typeerror: do not know how to serialize a bigint at json.stringify ()
TypeError: Do not know how to serialize a BigInt at JSON.stringify ( ) : r/nextjs
December 5, 2023 - If the BigInt in question represents an ID from the database (e.g. the SQL schema has the ID as BIGINT), then a string is the best option since we don't do arithmetic operations on an ID field, and a string is guaranteed to return a value that when passed back into the BigInt constructor is the same, whereas with Number, this is not a guarantee. ... Thanks for the suggestion. I’ll change it to string. ... you are my hero. I'm making an incremental game, with really big numbers, and yes, JS can handle them to some extent but steam api was failing to pass it to the sockets ... I also had similar problem while serialising. I have passed a custom function to serialiser like this: JSON.stringify(data, (_, v) => typeof v === "bigint" ?
Top answer
1 of 5
65

Not with built-in JSON.parse. You'll need to parse it manually and treat values as string (if you want to do arithmetics with them there is bignumber.js) You can use Douglas Crockford JSON.js library as a base for your parser.

EDIT2 ( 7 years after original answer ) - it might soon be possible to solve this using standard JSON api. Have a look at this TC39 proposal to add access to source string to a reviver function - https://github.com/tc39/proposal-json-parse-with-source

EDIT1: I created a package for you :)

var JSONbig = require('json-bigint');

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

console.log('node.js bult-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\nbig number JSON:');
var r1 = JSONbig.parse(json);
console.log('JSON.parse(input).value : ', r1.value.toString());
console.log('JSON.stringify(JSON.parse(input)):', JSONbig.stringify(r1));

Output:

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

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


big number JSON:
JSON.parse(input).value :  9223372036854775807
JSON.stringify(JSON.parse(input)): {"value":9223372036854775807,"v2":123}
2 of 5
3

After searching something more clean - and finding only libs like jsonbigint, I just wrote my own solution. Is not the best, but it solves my problem. For those that are using Axios you can use it on transformResponse callback (this was my original problem - Axios parses the JSON and all bigInts cames wrong),

const jsonStr = `{"myBigInt":6028792033986383748, "someStr":"hello guys", "someNumber":123}`
const result = JSON.parse(jsonStr, (key, value) => {
 if (typeof value === 'number' && !Number.isSafeInteger(value)) {
     let strBig = jsonStr.match(new RegExp(`(?:"${key}":)(.*?)(?:,)`))[1] // get the original value using regex expression 
     return strBig //should be BigInt(strBig) - BigInt function is not working in this snippet
 }
 return value
   })
   console.log({
   "original": JSON.parse(jsonStr),
   "handled": result
   })

🌐
npm
npmjs.com › package › json-with-bigint
json-with-bigint - npm
January 13, 2026 - Download json-with-bigint.min.js from this repository to your project's folder and use it
      » npm install json-with-bigint
    
Published   Feb 28, 2026
Version   3.5.7
Author   Ivan Korolenko
🌐
Medium
medium.com › @tanmaypanda752 › how-to-parse-bigint-from-json-682f03c4e675
How to Parse BigInt from JSON. Learn how to safely parse large… | by Tanmaypanda | Medium
April 10, 2025 - This is safe because JSON doesn’t support BigInt, so putting it in quotes prevents the number corruption.
Top answer
1 of 5
16

TLDR;

You may employ JSON.parse() reviver parameter

Detailed Solution

To control JSON.parse() behavior that way, you can make use of the second parameter of JSON.parse (reviver) - the function that pre-processes key-value pairs (and may potentially pass desired values to BigInt()).

Yet, the values recognized as numbers will still be coerced (the credit for pinpointing this issue goes to @YohanesGultom).

To get around this, you may enquote your big numbers (to turn them into strings) in your source JSON string, so that their values are preserved upon converting to bigint.

As long as you wish to convert to bigint only certain numbers, you would need to pick up appropriate criteria (e.g. to check whether the value exceeds Number.MAX_SAFE_INTEGER with Number.isSafeInteger(), as @PeterSeliger has suggested).

Thus, your problem may be solved with something, like this:

Copy// source JSON string

const input = `{"foo":[[0],[64],[89],[97]],"bar":[[2323866757078990912,144636906343245838,441695983932742154,163402272522524744],[2477006750808014916,78818525534420994],[18577623609266200],[9008333127155712]]}`


// function that implements desired criteria
// to separate *big numbers* from *small* ones
//
// (works for input parameter num of type number/string)

const isBigNumber = num => !Number.isSafeInteger(+num)


// function that enquotes *big numbers* matching
// desired criteria into double quotes inside
// JSON string
//
// (function checking for *big numbers* may be
// passed as a second parameter for flexibility)

const enquoteBigNumber = (jsonString, bigNumChecker) =>
    jsonString
        .replaceAll(
            /([:\s\[,]*)(\d+)([\s,\]]*)/g,
            (matchingSubstr, prefix, bigNum, suffix) =>
                bigNumChecker(bigNum)
                    ? `${prefix}"${bigNum}"${suffix}`
                    : matchingSubstr
        )


// parser that turns matching *big numbers* in
// source JSON string to bigint

const parseWithBigInt = (jsonString, bigNumChecker) =>
    JSON.parse(
        enquoteBigNumber(jsonString, bigNumChecker),
        (key, value) =>
            !isNaN(value) && bigNumChecker(value)
                ? BigInt(value)
                : value
    )

// resulting output

const output = parseWithBigInt(input, isBigNumber)


console.log("output.foo[1][0]: \n", output.foo[1][0], `(type: ${typeof output.foo[1][0]})`)
console.log("output.bar[0][0]: \n", output.bar[0][0].toString(), `(type: ${typeof output.bar[0][0]})`)
Copy.as-console-wrapper{min-height: 100% !important;}
Run code snippetEdit code snippet Hide Results Copy to answer Expand

Note: you may find RegExp pattern to match strings of digits among JSON values not quite robust, so feel free to come up with yours (as mine was the quickest I managed to pick off the top of my head for demo purposes)

Note: you may still opt in for some library, as it was suggested by @YohanesGultom, yet adding 10k to your client bundle or 37k to your server-side dependencies (possibly, to docker image size) for that sole purpose may not be quite reasonable.

2 of 5
5

You can try my library that solves this problem: https://www.npmjs.com/package/json-with-bigint

Example:

Copyimport { JSONParse } from 'json-with-bigint';
    
const yourJSON = `{"someValue":42,"someBigValue":10000000000000000365}`;

JSONParse(yourJSON); // { someValue: 42, someBigValue: 10000000000000000365n }

Library will automatically figure out what values are BigInt, so no need to pass a list of specific keys with BigInt values.

It also supports consistent round-trip operations (parse - stringify - parse). Deserialized values will be the same as the ones you serialized initially and vice versa.

Copyimport { JSONParse, JSONStringify } from 'json-with-bigint';
    
const yourJSON = `{"someValue":42,"someBigValue":10000000000000000365}`;

JSONParse(yourJSON); // { someValue: 42, someBigValue: 10000000000000000365n }
JSONStringify(data); // '{"someValue":42,"someBigValue":10000000000000000365}'
JSONParse(JSONStringify(data)); // { someValue: 42, someBigValue: 10000000000000000365n }
Find elsewhere
Top answer
1 of 9
38

You could use the replacer argument for JSON.stringify like this:

const obj = {
  foo: 'abc',
  bar: 781,
  qux: 9n
}

JSON.stringify(obj, (_, v) => typeof v === 'bigint' ? v.toString() : v)
2 of 9
24

BigInt to JSON in 2024

There is no single correct method to use in every case. As explained by Jakob Kummerow in a discussion in a Google Chrome Labs GitHub repository:

Working as intended/spec'ed: https://tc39.es/proposal-bigint/#sec-serializejsonproperty (step 10).

In short, the background is that JSON is so commonly used among all sorts of different systems and programming languages that it is effectively impossible to add anything to the format without breaking compatibility in some crucial case.

You can define your own .toJSON() function, and pass a corresponding "reviver" function as an argument to JSON.parse(). That way, at least you have control over any (backwards) compatibility issues.

Typescript (and Javascript), by default, will not create a BigInt value when parsing JSON no matter how large the number is. It will parse it as the nearest number, silently ignoring errors with precision.

There are a few ways to work around this, but they depend on you having control over both stringfying and parsing the JSON. Otherwise, the JSON you produce may not parse correctly because it violates standards.

Here are a few methods:

Use a structured string as a go-between

What I propose is to stringify BigInt as a quoted string ending in n, which is very similar to the standard way of specifying BigInt numbers, making them human-readable and easy to convert automatically. To accomplish this, you need to define a replacer and reviver function:

function bigIntReplacer(key: string, value: any): any {
  if (typeof value === "bigint") {
    return value.toString() + 'n';
  }
  return value;
}

function bigIntReviver(key: string, value: any): any {
  if (typeof value === 'string' && /^\d+n$/.test(value)) {
    return BigInt(value.slice(0, -1));
  }
  return value;
}

Now you can use these when calling JSON.stringify and JSON.parse like this:

const bigInteger = BigInt(Number.MAX_SAFE_INTEGER) * BigInt(8);

// Stringify using the replacer
const jsonBigInteger = JSON.stringify(bigInteger, bigIntReplacer);

// Print JSON to show it is a string
console.log(`As JSON, it is a ${typeof jsonBigInteger} containing: ${jsonBigInteger}`);

// Parse it from JSON
const fromJsonBigInteger = JSON.parse(jsonBigInteger, bigIntReviver);

// Print that number to show it is a bigint
console.log(`After passing through JSON, it is a ${typeof fromJsonBigInteger} containing ${fromJsonBigInteger.toString()}`);

Use an object as a go-between

Another method, although more verbose, is to use an object as a go-between. You can serialize your BigInt as an object that contains a field indicating that the object is a BigInt and another field holding the value. There is a bignumberify library that uses this method. It relies on the fact that JSON.stringify accepts a replacer function, and JSON.parse accepts a reviver function, both as an optional second parameter.

The author of that library gives an example of what a BigInt holding 125000n would serialize as:

{ 
  "type": "BigInt", 
  "hex": "0x01e848"
}

Their library relies on a function that must be passed to the JSON.stringify:

const jsonStr = JSON.stringify(obj, bigNumberify.stringify);

This is great because it avoids potential conflicts with other libraries and future modifications to the standards that are caused by modifying BigInt's prototype.

However, I think an object like that adds bloat while preventing the value from being human-readable (unless you consider hexadecimal to be human-readable). It also eliminates a major benefit of JSON, which is the direct correlation between the structure in JSON and the structure when parsed. A compatible parser will produce a different tree than standard ones would. I prefer a method that maintains the precision of the string method with the convenience of the number method and without the bloat of the object method.

Use strings as a go-between

WARNING: Modifying the prototype of standard Javascript objects is discouraged for very good reasons. If you are publishing a library, PLEASE DO NOT DO IT!

If you convert your BigInt into a string, it will be parsed as one. However, this may be acceptable when you know which field will be a string. You can just convert it explicitly when you encounter it. To do this, you can modify the prototype of BigInt as described by Holger Jeromin.

// eslint-disable-next-line @typescript-eslint/no-redeclare
interface BigInt {
    /** Convert to BigInt to string form in JSON.stringify */
    toJSON: () => string;
}
BigInt.prototype.toJSON = function () {
    return this.toString();
};

Or, if you're not using strict Typescript:

BigInt.prototype["toJSON"] = function () {
  return this.toString();
};

Someone with the paradoxical username noskill24 suggested a polyfill that ensures there is no existing .toJSON() before installing it:

// Polyfill: BigInt.prototype.toJSON 

(function(global, undefined) {
  if (global.BigInt.prototype.toJSON === undefined) {
    global.Object.defineProperty(global.BigInt.prototype, "toJSON", {
        value: function() { return this.toString(); },
        configurable: true,
        enumerable: false,
        writable: true
    });
  }
})(window !== void 0 ? window : typeof global !== void 0 ? global : typeof self !== void 0 ? self : this);

Use numbers as a go-between

You could just convert to a Number and let that get serialized as JSON. This method looks exactly like the previous one, except you'll use Number(this) instead of this.toString().

WARNING: This method has a major flaw. It loses precision. This means the number you receive might be close to the number you sent, but not exactly the same.

--

No method is perfect, but I hope this has been a good summary of the available options.

🌐
CodeSandbox
codesandbox.io › examples › package › json-bigint
json-bigint examples - CodeSandbox
react-native-agoraAgora RTC SDK For React Native · lipengzhou/toutiao-publish · nextjs-ts-reduxtookit-tailwindcssSimple starter template · nextjs-ts-reduxtookit-tailwindcssSimple starter template · node_characteraiUnofficial Character AI wrapper for node. Find more examples or templates · AboutJSON.parse with bigints support17,079,122Weekly Downloads · Latest version1.0.0 · LicenseMIT · External Links · github.com/sidorares/json-bigint#readme ·
🌐
npm
npmjs.com › package › json-bigint-patch
json-bigint-patch - npm
JSON.parse/stringify with bigints support.
      » npm install json-bigint-patch
    
Published   Nov 14, 2025
Version   0.0.9
Author   Arda TANRIKULU
🌐
Rasc
blog.rasc.ch › 2019 › 01 › js-bigint-json.html
JavaScript BigInt and JSON
January 4, 2019 - In my previous blog post, I took a closer look at the new numeric type BigInt in JavaScript. I wrote in my previous blog post that JSON does not support BigInt.
🌐
Medium
medium.com › glovo-engineering › cracking-the-code-js-bigint-and-the-art-of-future-proofing-your-app-2ef6d00f5d0c
Cracking the Code: JS, BigInt, and the Art of Future-Proofing Your App | by Victor Borisov | The Glovo Tech Blog | Medium
November 29, 2023 - Now that we found a way to parse JSON strings with BigInt, we should be good to go, right? Right… Not exactly. Since we are talking about an application with server side rendering, all major SSR frameworks (like next, nuxt and svelteKit) have a process called “hydration”. This is something that happens when the browser loads a page pre-rendered on nodejs, and then needs to instantiate UI components of the UI framework (like react...
🌐
CloudDefense.ai
clouddefense.ai › code › javascript › example › json-bigint
Top 10 Examples of json-bigint code in Javascript
Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'json-bigint' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
🌐
DEV Community
dev.to › benlesh › bigint-and-json-stringify-json-parse-2m8p
BigInt and JSON.stringify/JSON.parse - DEV Community
January 5, 2021 - It should be noted that how you choose to serialize your BigInts affects how you deserialize your BigInts. Generally, I serialize them by doing appending the "n" suffix to the end, similar to how we can declare a BigInt inline. (BigInt(0) and 0n yield the same result). Here we use JSON.stringify's second argument (It's not always null!!!
🌐
Medium
medium.com › @itstalwar15 › handling-bigint-in-axios-using-json-big-in-javascript-d915ae85ffc0
Handling BigInt in Axios using json-big in JavaScript | by Nikhil Talwar | Medium
November 5, 2020 - You can’t parse BigInt nor you can stringify and if you try to parse it without BigInt n it will convert into a different value. Let’s not use JSON.stringify and JSON.parse then?
🌐
GitHub
github.com › GoogleChromeLabs › jsbi › issues › 30
JSON.stringify() doesn't know how to serialize a BigInt · Issue #30 · GoogleChromeLabs/jsbi
August 14, 2019 - TypeError: Do not know how to serialize a BigInt at JSON.stringify (<anonymous>) 39 | toObject() { > 40 | return JSON.parse(JSON.stringify(this)); | ^ 41 | } Reactions are currently unavailable · No one assigned · No labels · No labels · No type · No projects ·
Author   cliffhall
🌐
npm
npmjs.com › package › json-bigint-native
json-bigint-native - npm
February 1, 2022 - Note that this is a dangerous behavior as it breaks the default functionality of being able to convert back-and-forth without data type changes (as this will convert all BigInts to be-and-stay strings). ... var JSONbig = require('json-bigint-native'); var JSONbigString = require('json-bigint-native')({ storeAsString: true }); var key = '{ "key": 1234567890123456789 }'; console.log('\n\nStoring the BigInt as a string, instead of a BigNumber'); 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 );
      » npm install json-bigint-native
    
Published   Feb 01, 2022
Version   1.2.0
🌐
Js
react-querybuilder.js.org › api › react-querybuilder › functions › bigIntJsonStringifyReplacer
bigIntJsonStringifyReplacer() | React Query Builder
"Replacer" method for JSON.stringify's second argument. Converts bigint values to objects with a $bigint property having a value of a string representation of the actual bigint-type value.
🌐
GitHub
github.com › tc39 › proposal-bigint › issues › 24
Support JSON serialisation of BigInt values · Issue #24 · tc39/proposal-bigint
March 17, 2017 - The abstract operation SerializeJSONProperty needs to be patched, so that JSON.stringify(1n) returns "1" instead of undefined: If Type(value) is Integer, then return a string representing value, wi...
Author   claudepache