{"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"},"_id":"json-bignum@0.0.2","dist":{"shasum":"6e5a403c35400160dfa474096f6ee9a29d164ae3","tarball":"http://registry-npm.ywwl.com/json-bignum/download/json-bignum-0.0.2.tgz","integrity":"sha512-IvSXSi5V8IFbOz+/4PBFcSguiaLIrpj8vFHvbcYXbFtx2OpX/ceADly3WCuZTb+EVvEoblh1/8TNy8/GOLyx0w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCheDnOOEnkmpWi7251BaSiqHttM/4P9ZHwk6fCvXOepAIgWWg7SLa8Ff46FBP46pGy2xSZlYrWfsuzkd4mPijLKeI="}],"size":7553,"noattachment":false,"key":"/json-bignum/-/json-bignum-0.0.2.tgz"},"_npmVersion":"1.1.69","_npmUser":{"name":"datalanche","email":"contact@datalanche.com"},"maintainers":[{"name":"datalanche","email":"contact@datalanche.com"}],"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","publish_time":1364228389033,"_cnpm_publish_time":1364228389033,"dist-tags":{"latest":"0.0.3"}}