JSFiddle - React, Tailwind, and code Playground
JavaScript
BigInt.prototype.toJSON = function(){
return this.toString();
}
const jsonReviver = (key, val) => (key === "bigIntDemo") ? BigInt(val) : val;
const origin = {
bigIntDemo: BigInt(Number.MAX_SAFE_INTEGER) * 2n,
number: Number.MAX_SAFE_INTEGER,
};
const json = JSON.stringify(origin);
const parsed = JSON.parse(json, jsonReviver);
console.clear();
console.log("origin", origin);
console.log("json", json);
console.log("parsed", parsed);