{"_id":"json-bignum","_rev":"410977","name":"json-bignum","description":"Node.js JSON replacement which handles 64-bit integers and arbitrary-precision decimals.","dist-tags":{"latest":"0.0.3"},"maintainers":[{"name":"datalanche","email":"contact@datalanche.com"}],"time":{"modified":"2021-08-04T05:08:25.000Z","created":"2013-03-22T22:04:32.947Z","0.0.3":"2014-04-18T19:21:16.186Z","0.0.2":"2013-03-25T16:19:49.033Z","0.0.1":"2013-03-22T22:04:32.947Z"},"users":{},"author":{"name":"Datalanche, Inc.","url":"https://www.datalanche.com"},"repository":{"type":"git","url":"https://github.com/datalanche/json-bignum.git"},"versions":{"0.0.3":{"author":{"name":"Datalanche, Inc.","url":"https://www.datalanche.com"},"name":"json-bignum","homepage":"https://github.com/datalanche/json-bignum","description":"Node.js JSON replacement which handles 64-bit integers and arbitrary-precision decimals.","version":"0.0.3","repository":{"type":"git","url":"https://github.com/datalanche/json-bignum.git"},"main":"lib/index.js","directories":{"lib":"./lib"},"licenses":[{"type":"MIT","url":"https://github.com/datalanche/json-bignum/raw/master/LICENSE"}],"engines":{"node":">=0.8"},"bugs":{"url":"https://github.com/datalanche/json-bignum/issues"},"_id":"json-bignum@0.0.3","dist":{"shasum":"41163b50436c773d82424dbc20ed70db7604b8d7","size":7700,"noattachment":false,"key":"/json-bignum/-/json-bignum-0.0.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/json-bignum/download/json-bignum-0.0.3.tgz"},"_from":".","_npmVersion":"1.3.8","_npmUser":{"name":"datalanche","email":"contact@datalanche.com"},"maintainers":[{"name":"datalanche","email":"contact@datalanche.com"}],"publish_time":1397848876186,"_cnpm_publish_time":1397848876186,"_hasShrinkwrap":false},"0.0.2":{"author":{"name":"Datalanche, Inc.","url":"https://www.datalanche.com"},"name":"json-bignum","homepage":"https://github.com/datalanche/json-bignum","description":"Node.js JSON replacement which handles 64-bit integers and arbitrary-precision decimals.","version":"0.0.2","repository":{"type":"git","url":"https://github.com/datalanche/json-bignum.git"},"main":"lib/index.js","directories":{"lib":"./lib"},"licenses":[{"type":"MIT","url":"https://github.com/datalanche/json-bignum/raw/master/LICENSE"}],"engines":{"node":">=0.8"},"dependencies":{"bigdecimal":"0.6.1"},"readmeFilename":"README.md","_id":"json-bignum@0.0.2","dist":{"shasum":"6e5a403c35400160dfa474096f6ee9a29d164ae3","size":7553,"noattachment":false,"key":"/json-bignum/-/json-bignum-0.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/json-bignum/download/json-bignum-0.0.2.tgz"},"_npmVersion":"1.1.69","_npmUser":{"name":"datalanche","email":"contact@datalanche.com"},"maintainers":[{"name":"datalanche","email":"contact@datalanche.com"}],"publish_time":1364228389033,"_cnpm_publish_time":1364228389033,"_hasShrinkwrap":false},"0.0.1":{"author":{"name":"Datalanche, Inc.","url":"https://www.datalanche.com"},"name":"json-bignum","homepage":"https://github.com/datalanche/json-bignum","description":"Node.js JSON replacement which handles 64-bit integers and arbitrary-precision decimals.","version":"0.0.1","repository":{"type":"git","url":"https://github.com/datalanche/json-bignum.git"},"main":"lib/index.js","directories":{"lib":"./lib"},"licenses":[{"type":"MIT","url":"https://github.com/datalanche/json-bignum/raw/master/LICENSE"}],"engines":{"node":">=0.8"},"dependencies":{"bigdecimal":"0.6.1"},"readmeFilename":"README.md","_id":"json-bignum@0.0.1","dist":{"shasum":"af5c51cb56fa413f544fa38f8a7aecce3e00affa","size":7548,"noattachment":false,"key":"/json-bignum/-/json-bignum-0.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/json-bignum/download/json-bignum-0.0.1.tgz"},"_npmVersion":"1.1.69","_npmUser":{"name":"datalanche","email":"contact@datalanche.com"},"maintainers":[{"name":"datalanche","email":"contact@datalanche.com"}],"publish_time":1363989872947,"_cnpm_publish_time":1363989872947,"_hasShrinkwrap":false}},"readme":"json-bignum\n===========\n\nNode.js JSON replacement which handles 64-bit integers and arbitrary-precision decimals. It is a modified version of [Douglas Crockford's JSON library](https://github.com/douglascrockford/JSON-js). Although it can handle 64-bit integers and arbitrary-precision decimals, it is slower than the built-in JSON functions.\n\n## Install\n\n    $ npm install json-bignum\n\n## Usage\n\n### parse()\n\n```js\nvar bignumJSON = require('json-bignum');\n\nvar obj = bignumJSON.parse('{ \"decimal\": -9223372036854775807.4237482374983253298159 }');\n```\n\n### stringify()\n\n```js\nvar bignumJSON = require('json-bignum');\n\nvar obj = {\n    bigint: new bignumJSON.BigNumber('92233720368547758074237482374983253298159'),\n    decimal: new bignumJSON.BigNumber('-9223372036854775807.4237482374983253298159'),\n};\n\nconsole.log(bignumJSON.stringify(obj));\n```\n\n### BigNumber\n\nThe ```BigNumber``` class simply stores the number as a string. It does not support arithmetic, but if you need that here are some excellent libraries.\n\n* [BigDecimal.js](https://github.com/iriscouch/bigdecimal.js): a literal port of Java's ```BigInteger``` and ```BigDecimal``` classes.\n* [bigint](https://github.com/substack/node-bigint): Big integer arithmetic using GMP.\n* [bignum](https://github.com/justmoon/node-bignum): Big integer arithmetic using OpenSSL.\n\n```js\n// example using BigDecimal.js\n\nvar bignumJSON = require('json-bignum');\nvar bigdecimal = require('bigdecimal');\n\nvar jsonStr = '{\"normal\":-922337203.234,\"big\":-9223372036854775807.4237482374983253298159}';\nvar jsonObj = bignumJSON.parse(jsonStr);\n\nvar a = new bigdecimal.BigDecimal(jsonObj.normal.toString());\nvar b = new bigdecimal.BigDecimal(jsonObj.big.toString());\nvar sum = a.add(b);\n\njsonObj.sum = new bignumJSON.BigNumber(sum.toString());\n\nconsole.log(bignumJSON.stringify(jsonObj));\n```\n\n## Caveats\n\nIt is not recommended to mix calls to ```JSON``` and ```bignumJSON```. For example, ```JSON.stringify()``` does not know how to parse ```BigNumber```.\n\n## Benchmark\n\nBelow shows the result of the benchmark on my machine.\n\n    $ node benchmark.js\n    10000 calls of JSON.parse():                                   26.746847 ms\n    10000 calls of JSON.stringify():                               20.824071 ms\n    10000 calls of bignumJSON.parse() with bignums in JSON:        221.945307 ms\n    10000 calls of bignumJSON.parse() without bignums in JSON:     150.626292 ms\n    10000 calls of bignumJSON.stringify() with bignums in JSON:    64.166056 ms\n    10000 calls of bignumJSON.stringify() without bignums in JSON: 61.860016 ms\n","_attachments":{},"homepage":"https://github.com/datalanche/json-bignum","bugs":{"url":"https://github.com/datalanche/json-bignum/issues"}}