{"_id":"@cardanosolutions/json-bigint","_rev":"6-6726ebead843dba18354e3a12d720726","name":"@cardanosolutions/json-bigint","dist-tags":{"latest":"1.1.0"},"versions":{"1.0.0":{"name":"@cardanosolutions/json-bigint","version":"1.0.0","keywords":["JSON","bigint","bignumber","parse","json"],"author":{"name":"Andrey Sidorov","email":"sidorares@yandex.ru"},"license":"MIT","_id":"@cardanosolutions/json-bigint@1.0.0","maintainers":[{"name":"rhyslbw","email":"rhyslbw@gmail.com"},{"name":"ktorz","email":"matthias.benkort@gmail.com"}],"homepage":"https://github.com/sidorares/json-bigint#readme","bugs":{"url":"https://github.com/sidorares/json-bigint/issues"},"dist":{"shasum":"11a66d251ae34c605a9e7d31f01421721a8677fd","tarball":"https://registry.npmjs.org/@cardanosolutions/json-bigint/-/json-bigint-1.0.0.tgz","fileCount":6,"integrity":"sha512-46ts2s0W63nzqHMhaXKACeY0GDWdnPet9wqOWtb8X3Y5LzokcaDKupLO2eHUwlvQyFzD9gxJlWPi/LqZPkn4oQ==","signatures":[{"sig":"MEUCIDG/cNOVkPjpm3WUom8F7DQRsvNRmNqZma6FCSNzciHUAiEAlpCa9FEvRwQpaEB00isX0k46XsRAZcHvK9Rswr3Bszo=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":37907,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh2CM9CRA9TVsSAnZWagAAhaoP+gNanH/HKmbfJskJ1s9V\nCPQmV86necKtKaE1d/GVtwHTVYXvOohGGSI8bTOwzo1htjWn3BR3XZrIa6Bu\n7PTndpreFeh8O8lZbqhklTJDPQDhRk/ekuHpZVBPEHmDOKIhAB3VYkWYLxNv\nOwAphdkMgt3H32eO3QKxLBrbE8EGJyfE+ZRmnekYU077Ue2/HCZPd43Tk14C\nnFjMYIzmMyx+O9L4i5EYyYhGzc8iNFb8zOQHe7Qn2YFnSTYKqtVRdkw3MRYu\nEDzjPHKuT7hkgGDi8/iJbtxpTHLDVTd+4nJmaQBsPtxKDDaLsRGaAVp44KdQ\nCmc13J1udqcd/B6UocjZrFHWO8qrWfbqunQbbXLnLwu8XE2SG86ctyOcUUwI\nR4uzdVd5YPM3kJJdBTve8pKaeRPBJnnDimOzf8q4RC6j5Yfdpvlq9u5W+LdH\nkSzoHeKvr4kpoqLQE4rfIzyF3OFR1XFyqVwMWkT9A6IDbSH76gwJvdzrVkRf\nWaOk1O9eG8Q2BmEuOnACDFRz794wOe0xF1Ee9ABlPQKrRQfGbg8JxSJOXwDh\nnKuYiC7dNkdk5gfeCyh5Q8tM3Lej9ohIErorn7wCeyqSyXmiZo7GglJFGn0E\nwfPNHISEII0qCqprsOmiXOrrzDbbOrfjCoSup9rZSSN7ajRV8BPwZcJzw0kE\ntfzX\r\n=pTmH\r\n-----END PGP SIGNATURE-----\r\n"},"main":"index.js","gitHead":"d277387d7750ff4e698677d0aa0db97ebb60c581","scripts":{"test":"./node_modules/mocha/bin/mocha -R spec --check-leaks test/*-test.js"},"_npmUser":{"name":"rhyslbw","email":"rhyslbw@gmail.com"},"repository":{"url":"git+ssh://git@github.com/sidorares/json-bigint.git","type":"git"},"_npmVersion":"6.14.8","description":"JSON.parse with bigints support, considering scientific notation","directories":{},"_nodeVersion":"14.15.0","dependencies":{"bignumber.js":"^9.0.0"},"_hasShrinkwrap":false,"devDependencies":{"chai":"4.2.0","mocha":"8.0.1"},"_npmOperationalInternal":{"tmp":"tmp/json-bigint_1.0.0_1631861657852_0.6350077328038235","host":"s3://npm-registry-packages"}},"1.0.1":{"name":"@cardanosolutions/json-bigint","version":"1.0.1","keywords":["JSON","bigint","bignumber","parse","json"],"author":{"name":"Andrey Sidorov","email":"sidorares@yandex.ru"},"license":"MIT","_id":"@cardanosolutions/json-bigint@1.0.1","maintainers":[{"name":"rhyslbw","email":"rhyslbw@gmail.com"},{"name":"ktorz","email":"matthias.benkort@gmail.com"}],"contributors":[{"name":"Matthias Benkort"}],"dist":{"shasum":"077dad78f010c2fd195cf035b1b680dc6d98d50b","tarball":"https://registry.npmjs.org/@cardanosolutions/json-bigint/-/json-bigint-1.0.1.tgz","fileCount":8,"integrity":"sha512-mbYL6jtHqMFCZnTFhmkmoeDzHMBino0gMiGQnOJE7CwzZzkK2HCpH0MTBk+84QDadMEGX7iFt7uB+levm1a+bQ==","signatures":[{"sig":"MEUCIDFTlsgQcVWf6i1mZheNWjPxlsSITEBiWi58ryMRNw7/AiEAp3Och2++91K296ON907yYc5ayfuK3zQY8rIMVr/8vgQ=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":37977},"main":"index.js","scripts":{"test":"./node_modules/mocha/bin/mocha -R spec --check-leaks test/*-test.js"},"_npmUser":{"name":"ktorz","email":"matthias.benkort@gmail.com"},"repository":{"url":"git@github.com:sidorares/json-bigint.git","type":"git"},"description":"JSON.parse with bigint support and correct handling of scientific notation","directories":{},"licenseText":"The MIT License (MIT)\n\nCopyright (c) 2013 Andrey Sidorov\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","dependencies":{"bignumber.js":"^9.0.0"},"_hasShrinkwrap":false,"devDependencies":{"chai":"4.2.0","mocha":"8.0.1"},"_npmOperationalInternal":{"tmp":"tmp/json-bigint_1.0.1_1690734450413_0.06675921327835499","host":"s3://npm-registry-packages"}},"1.0.2":{"name":"@cardanosolutions/json-bigint","version":"1.0.2","keywords":["JSON","bigint","bignumber","parse","json"],"author":{"name":"Andrey Sidorov","email":"sidorares@yandex.ru"},"license":"MIT","_id":"@cardanosolutions/json-bigint@1.0.2","maintainers":[{"name":"rhyslbw","email":"rhyslbw@gmail.com"},{"name":"ktorz","email":"matthias.benkort@gmail.com"}],"contributors":[{"name":"Matthias Benkort"}],"homepage":"https://github.com/sidorares/json-bigint#readme","bugs":{"url":"https://github.com/sidorares/json-bigint/issues"},"dist":{"shasum":"a1f116d16f9dbda4feaba5b0d2c1b39dd0c204f5","tarball":"https://registry.npmjs.org/@cardanosolutions/json-bigint/-/json-bigint-1.0.2.tgz","fileCount":6,"integrity":"sha512-hRgKDFRR5zW6vv6KoymE1PuhKk8hxA/F5YsH37ghIFIYnWAMbVoQ7xRKAT5AEy9HrqWM6HxNQLIZ3r3omg96/w==","signatures":[{"sig":"MEUCIAYiwwbn5uz9iFI56vL7p44Q288uslWS98yiOQRpnGCwAiEA3HCRjJEVZX3IAl+D5YiVGYdE4XYFdyyzSFSa0htRh+M=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":37982},"main":"index.js","gitHead":"7e83e19fc428ca4b7878ccda71631ce01991b029","scripts":{"test":"./node_modules/mocha/bin/mocha.js -R spec --check-leaks test/*-test.js"},"_npmUser":{"name":"ktorz","email":"matthias.benkort@gmail.com"},"repository":{"url":"git+ssh://git@github.com/sidorares/json-bigint.git","type":"git"},"_npmVersion":"10.5.2","description":"JSON.parse with bigint support and correct handling of scientific notation","directories":{},"_nodeVersion":"20.13.1","dependencies":{"bignumber.js":"^9.3.1"},"_hasShrinkwrap":false,"devDependencies":{"chai":"4.2.0","mocha":"^11.7.2"},"_npmOperationalInternal":{"tmp":"tmp/json-bigint_1.0.2_1758224697505_0.2361346904587498","host":"s3://npm-registry-packages-npm-production"}},"1.1.0":{"name":"@cardanosolutions/json-bigint","version":"1.1.0","description":"JSON.parse with bigint support and correct handling of scientific notation","main":"index.js","scripts":{"test":"./node_modules/mocha/bin/mocha.js -R spec --check-leaks test/*-test.js"},"repository":{"type":"git","url":"git+ssh://git@github.com/sidorares/json-bigint.git"},"keywords":["JSON","bigint","bignumber","parse","json"],"author":{"name":"Andrey Sidorov","email":"sidorares@yandex.ru"},"contributors":[{"name":"Matthias Benkort"}],"license":"MIT","dependencies":{},"devDependencies":{"chai":"4.2.0","mocha":"^11.7.2"},"_id":"@cardanosolutions/json-bigint@1.1.0","gitHead":"950c151cb74f843a1f4448735ae9f9707d748089","bugs":{"url":"https://github.com/sidorares/json-bigint/issues"},"homepage":"https://github.com/sidorares/json-bigint#readme","_nodeVersion":"22.20.0","_npmVersion":"10.9.3","dist":{"integrity":"sha512-Pdgz18cSwLKKgheOqW/dqbzNI+CliNT4AdaKaKY/P++J9qLxIB8MITCurlzbaFWV3W4nmK0CRQwI1yvuArmjFg==","shasum":"dddfa10825de8c1856d8ec945db8f4e366f8cef3","tarball":"https://registry.npmjs.org/@cardanosolutions/json-bigint/-/json-bigint-1.1.0.tgz","fileCount":6,"unpackedSize":37751,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIDvEHhQPWLxKd0mzm3rS8vCfF1f+MEceOdf6G+cGsj0TAiBBYtPelrhJ2byLBsgPdJXHyf7qeOWJbS7ZOAr1c6vvdQ=="}]},"_npmUser":{"name":"ktorz","email":"matthias.benkort@gmail.com"},"directories":{},"maintainers":[{"name":"rhyslbw","email":"rhyslbw@gmail.com"},{"name":"ktorz","email":"matthias.benkort@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/json-bigint_1.1.0_1765983450550_0.19951573660575916"},"_hasShrinkwrap":false}},"time":{"created":"2021-09-17T06:54:17.774Z","modified":"2025-12-17T14:57:30.931Z","1.0.0":"2021-09-17T06:54:18.045Z","1.0.1":"2023-07-30T16:27:30.563Z","1.0.2":"2025-09-18T19:44:57.708Z","1.1.0":"2025-12-17T14:57:30.700Z"},"bugs":{"url":"https://github.com/sidorares/json-bigint/issues"},"author":{"name":"Andrey Sidorov","email":"sidorares@yandex.ru"},"license":"MIT","homepage":"https://github.com/sidorares/json-bigint#readme","keywords":["JSON","bigint","bignumber","parse","json"],"repository":{"type":"git","url":"git+ssh://git@github.com/sidorares/json-bigint.git"},"description":"JSON.parse with bigint support and correct handling of scientific notation","contributors":[{"name":"Matthias Benkort"}],"maintainers":[{"name":"rhyslbw","email":"rhyslbw@gmail.com"},{"name":"ktorz","email":"matthias.benkort@gmail.com"}],"readme":"# json-bigint\n\n[![Build Status](https://secure.travis-ci.org/sidorares/json-bigint.png)](http://travis-ci.org/sidorares/json-bigint)\n[![NPM](https://nodei.co/npm/json-bigint.png?downloads=true&stars=true)](https://nodei.co/npm/json-bigint/)\n\nJSON.parse/stringify with bigints support. Based on Douglas Crockford [JSON.js](https://github.com/douglascrockford/JSON-js) package and [bignumber.js](https://github.com/MikeMcl/bignumber.js) library.\n\nNative `Bigint` was added to JS recently, so we added an option to leverage it instead of `bignumber.js`. However, the parsing with native `BigInt` is kept an option for backward compability.\n\nWhile 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 }`\n\n==========\n\nexample:\n\n```js\nvar JSONbig = require('json-bigint');\n\nvar json = '{ \"value\" : 9223372036854775807, \"v2\": 123 }';\nconsole.log('Input:', json);\nconsole.log('');\n\nconsole.log('node.js built-in JSON:');\nvar r = JSON.parse(json);\nconsole.log('JSON.parse(input).value : ', r.value.toString());\nconsole.log('JSON.stringify(JSON.parse(input)):', JSON.stringify(r));\n\nconsole.log('\\n\\nbig number JSON:');\nvar r1 = JSONbig.parse(json);\nconsole.log('JSONbig.parse(input).value : ', r1.value.toString());\nconsole.log('JSONbig.stringify(JSONbig.parse(input)):', JSONbig.stringify(r1));\n```\n\nOutput:\n\n```\nInput: { \"value\" : 9223372036854775807, \"v2\": 123 }\n\nnode.js built-in JSON:\nJSON.parse(input).value :  9223372036854776000\nJSON.stringify(JSON.parse(input)): {\"value\":9223372036854776000,\"v2\":123}\n\n\nbig number JSON:\nJSONbig.parse(input).value :  9223372036854775807\nJSONbig.stringify(JSONbig.parse(input)): {\"value\":9223372036854775807,\"v2\":123}\n```\n\n### Options\n\nThe behaviour of the parser is somewhat configurable through 'options'\n\n#### options.strict, boolean, default false\n\nSpecifies the parsing should be \"strict\" towards reporting duplicate-keys in the parsed string.\nThe default follows what is allowed in standard json and resembles the behavior of JSON.parse, but overwrites any previous values with the last one assigned to the duplicate-key.\n\nSetting options.strict = true will fail-fast on such duplicate-key occurances and thus warn you upfront of possible lost information.\n\nexample:\n\n```js\nvar JSONbig = require('json-bigint');\nvar JSONstrict = require('json-bigint')({ strict: true });\n\nvar dupkeys = '{ \"dupkey\": \"value 1\", \"dupkey\": \"value 2\"}';\nconsole.log('\\n\\nDuplicate Key test with both lenient and strict JSON parsing');\nconsole.log('Input:', dupkeys);\nvar works = JSONbig.parse(dupkeys);\nconsole.log('JSON.parse(dupkeys).dupkey: %s', works.dupkey);\nvar fails = 'will stay like this';\ntry {\n  fails = JSONstrict.parse(dupkeys);\n  console.log('ERROR!! Should never get here');\n} catch (e) {\n  console.log(\n    'Succesfully catched expected exception on duplicate keys: %j',\n    e\n  );\n}\n```\n\nOutput\n\n```\nDuplicate Key test with big number JSON\nInput: { \"dupkey\": \"value 1\", \"dupkey\": \"value 2\"}\nJSON.parse(dupkeys).dupkey: value 2\nSuccesfully catched expected exception on duplicate keys: {\"name\":\"SyntaxError\",\"message\":\"Duplicate key \\\"dupkey\\\"\",\"at\":33,\"text\":\"{ \\\"dupkey\\\": \\\"value 1\\\", \\\"dupkey\\\": \\\"value 2\\\"}\"}\n\n```\n\n#### options.storeAsString, boolean, default false\n\nSpecifies if BigInts should be stored in the object as a string, rather than the default BigNumber.\n\nNote 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).\n\nexample:\n\n```js\nvar JSONbig = require('json-bigint');\nvar JSONbigString = require('json-bigint')({ storeAsString: true });\nvar key = '{ \"key\": 1234567890123456789 }';\nconsole.log('\\n\\nStoring the BigInt as a string, instead of a BigNumber');\nconsole.log('Input:', key);\nvar withInt = JSONbig.parse(key);\nvar withString = JSONbigString.parse(key);\nconsole.log(\n  'Default type: %s, With option type: %s',\n  typeof withInt.key,\n  typeof withString.key\n);\n```\n\nOutput\n\n```\nStoring the BigInt as a string, instead of a BigNumber\nInput: { \"key\": 1234567890123456789 }\nDefault type: object, With option type: string\n\n```\n\n#### options.useNativeBigInt, boolean, default false\n\nSpecifies if parser uses native BigInt instead of bignumber.js\n\nexample:\n\n```js\nvar JSONbig = require('json-bigint');\nvar JSONbigNative = require('json-bigint')({ useNativeBigInt: true });\nvar key = '{ \"key\": 993143214321423154315154321 }';\nconsole.log(`\\n\\nStoring the Number as native BigInt, instead of a BigNumber`);\nconsole.log('Input:', key);\nvar normal = JSONbig.parse(key);\nvar nativeBigInt = JSONbigNative.parse(key);\nconsole.log(\n  'Default type: %s, With option type: %s',\n  typeof normal.key,\n  typeof nativeBigInt.key\n);\n```\n\nOutput\n\n```\nStoring the Number as native BigInt, instead of a BigNumber\nInput: { \"key\": 993143214321423154315154321 }\nDefault type: object, With option type: bigint\n\n```\n\n#### options.alwaysParseAsBig, boolean, default false\n\nSpecifies if all numbers should be stored as BigNumber.\n\nNote 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)\n\nexample:\n\n```js\nvar JSONbig = require('json-bigint');\nvar JSONbigAlways = require('json-bigint')({ alwaysParseAsBig: true });\nvar key = '{ \"key\": 123 }'; // there is no need for BigNumber by default, but we're forcing it\nconsole.log(`\\n\\nStoring the Number as a BigNumber, instead of a Number`);\nconsole.log('Input:', key);\nvar normal = JSONbig.parse(key);\nvar always = JSONbigAlways.parse(key);\nconsole.log(\n  'Default type: %s, With option type: %s',\n  typeof normal.key,\n  typeof always.key\n);\n```\n\nOutput\n\n```\nStoring the Number as a BigNumber, instead of a Number\nInput: { \"key\": 123 }\nDefault type: number, With option type: object\n\n```\n\nIf you want to force all numbers to be parsed as native `BigInt`\n(you probably do! Otherwise any calulations become a real headache):\n\n```js\nvar JSONbig = require('json-bigint')({\n  alwaysParseAsBig: true,\n  useNativeBigInt: true,\n});\n```\n\n#### options.protoAction, boolean, default: \"error\". Possible values: \"error\", \"ignore\", \"preserve\"\n\n#### options.constructorAction, boolean, default: \"error\". Possible values: \"error\", \"ignore\", \"preserve\"\n\nControls how `__proto__` and `constructor` properties are treated. If set to \"error\" they are not allowed and\nparse() call will throw an error. If set to \"ignore\" the prroperty and it;s value is skipped from parsing and object building.\nIf set to \"preserve\" the `__proto__` property is set. One should be extra careful and make sure any other library consuming generated data\nis not vulnerable to prototype poisoning attacks.\n\nexample:\n\n```js\nvar JSONbigAlways = require('json-bigint')({ protoAction: 'ignore' });\nconst user = JSONbig.parse('{ \"__proto__\": { \"admin\": true }, \"id\": 12345 }');\n// => result is { id: 12345 }\n```\n\n### Links:\n\n- [RFC4627: The application/json Media Type for JavaScript Object Notation (JSON)](http://www.ietf.org/rfc/rfc4627.txt)\n- [Re: \\[Json\\] Limitations on number size?](http://www.ietf.org/mail-archive/web/json/current/msg00297.html)\n- [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)\n- [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)\n- [Large numbers erroneously rounded in Javascript](http://stackoverflow.com/questions/1379934/large-numbers-erroneously-rounded-in-javascript)\n\n### Note on native BigInt support\n\n#### Stringifying\n\nFull support out-of-the-box, stringifies BigInts as pure numbers (no quotes, no `n`)\n\n#### Limitations\n\n- Roundtrip operations\n\n`s === JSONbig.stringify(JSONbig.parse(s))` but\n\n`o !== JSONbig.parse(JSONbig.stringify(o))`\n\nwhen `o` has a value with something like `123n`.\n\n`JSONbig` stringify `123n` as `123`, which becomes `number` (aka `123` not `123n`) by default when being reparsed.\n\nThere is currently no consistent way to deal with this issue, so we decided to leave it, handling this specific case is then up to users.\n","readmeFilename":"README.md"}