{"_id":"json-bigint-rs","_rev":"2-5e3d40832451cc5e59e703da882bb5df","name":"json-bigint-rs","dist-tags":{"latest":"0.1.2"},"versions":{"0.1.1":{"name":"json-bigint-rs","version":"0.1.1","keywords":["json","bigint","rust","wasm","webassembly"],"license":"MIT","_id":"json-bigint-rs@0.1.1","maintainers":[{"name":"h2istudio","email":"h2istudio825@gmail.com"}],"dist":{"shasum":"7098a869051bad5c71d5d2bf04a798df0c4be16f","tarball":"https://registry.npmjs.org/json-bigint-rs/-/json-bigint-rs-0.1.1.tgz","fileCount":5,"integrity":"sha512-ezvCHb2kJ6IBmGnYSerUSDoBiQzGBzI/7sREGzeRl7oRNP83HFQDWNgPGb+4uz3ZavQ4mTxMRiOreZS7ggeLkw==","signatures":[{"sig":"MEQCIByZtgaKkClDg4GxTGnrSEZr1C75w0EzxGZdlHxYvoVNAiBH1AxTBE8jwDjGCOdqCCtEYBpNImiNNjMrKMKsWja33Q==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":33306},"main":"./index.js","type":"commonjs","types":"./index.d.ts","engines":{"node":">=22.19.0"},"exports":{".":{"types":"./index.d.ts","default":"./index.js","require":"./index.js"}},"_npmUser":{"name":"h2istudio","email":"h2istudio825@gmail.com"},"_npmVersion":"11.16.0","description":"Rust/WASM JSON BigInt support","directories":{},"sideEffects":false,"_nodeVersion":"24.18.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/json-bigint-rs_0.1.1_1788245701185_0.9306899329109037","host":"s3://npm-registry-packages-npm-production"}},"0.1.2":{"name":"json-bigint-rs","version":"0.1.2","description":"Rust/WASM JSON BigInt support","license":"MIT","type":"commonjs","main":"./index.js","types":"./index.d.ts","exports":{".":{"types":"./index.d.ts","require":"./index.js","default":"./index.js"}},"engines":{"node":">=22.19.0"},"keywords":["json","bigint","rust","wasm","webassembly"],"sideEffects":false,"_id":"json-bigint-rs@0.1.2","_nodeVersion":"24.18.0","_npmVersion":"11.16.0","dist":{"integrity":"sha512-QfypVogBW80XVqT5gDHwoKbQcMKg6JWC+8KNI4cQSAOEjHMYaxH54tMUBJwvMn/mb3WbWuzsfZXPw625hieo/Q==","shasum":"d0e99368ce538cad2cb30127f66333be5637f8f8","tarball":"https://registry.npmjs.org/json-bigint-rs/-/json-bigint-rs-0.1.2.tgz","fileCount":5,"unpackedSize":33266,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCICIMdzOnH6iJl3lY5GVa0nhwq8pdQxVa2FzJ2yoHsn0pAiEA1AJQUI2R9yh/sANoo3uZUP6Tq+ug4QDC2ibFd3s/jKo="}]},"_npmUser":{"name":"h2istudio","email":"h2istudio825@gmail.com"},"directories":{},"maintainers":[{"name":"h2istudio","email":"h2istudio825@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/json-bigint-rs_0.1.2_1788333631914_0.1064995845396226"},"_hasShrinkwrap":false}},"time":{"created":"2026-09-01T06:55:01.093Z","modified":"2026-09-02T07:20:32.252Z","0.1.1":"2026-09-01T06:55:01.330Z","0.1.2":"2026-09-02T07:20:32.072Z"},"license":"MIT","keywords":["json","bigint","rust","wasm","webassembly"],"description":"Rust/WASM JSON BigInt support","maintainers":[{"name":"h2istudio","email":"h2istudio825@gmail.com"}],"readme":"# json-bigint-rs\n\nHigh-performance, precision-safe JSON parsing for Node.js, backed by Rust and\nWebAssembly.\n\n`json-bigint-rs` preserves integer literals outside JavaScript's safe integer\nrange as exact decimal strings. It uses a Rust/WASM lexical preprocessor for\nlarge-integer detection, then delegates JSON validation and object construction\nto V8's native `JSON.parse` implementation.\n\nJavaScript `Number` values can represent integers exactly only within\n`Number.MIN_SAFE_INTEGER` and `Number.MAX_SAFE_INTEGER` (`-(2^53 - 1)` through\n`2^53 - 1`). Parsing a larger integer with the native JSON API can silently lose\nprecision:\n\n```js\nJSON.parse('{\"id\":9223372036854775807}').id;\n// 9223372036854776000 (precision has been lost)\n```\n\nWith `json-bigint-rs`, the original decimal representation is preserved:\n\n```js\nconst JSONBig = require('json-bigint-rs');\n\nJSONBig.parse('{\"id\":9223372036854775807}').id;\n// '9223372036854775807'\n```\n\n## Performance architecture\n\n- Performs a single `O(n)` lexical scan in Rust/WASM.\n- Rewrites only integer tokens outside JavaScript's safe integer range.\n- Does not construct an intermediate JSON syntax tree.\n- Does not allocate `BigNumber` objects or depend on an arbitrary-precision\n  number library.\n- Avoids allocating a WASM output buffer when no unsafe integers are present.\n- Delegates syntax validation and object construction to V8's optimized native\n  `JSON.parse` implementation.\n- Reuses native `JSON.stringify`, adding only the conversion required to encode\n  JavaScript `BigInt` values as precision-safe decimal strings.\n\nThe design assigns the linear scanning workload to Rust/WASM while retaining\nV8's mature, highly optimized JSON parser and serializer.\n\n## Benchmark\n\nAcross the five measured JSON workloads, `json-bigint-rs` delivered\n**2.86x–4.44x** the parsing throughput of `json-bigint@1.0.0`. This corresponds\nto a **185.7%–343.6% throughput increase** and a **65.0%–77.5% reduction in\nper-operation latency**.\n\n### Methodology\n\n- Compared `json-bigint-rs` against `json-bigint@1.0.0`.\n- Configured the original implementation with `{ storeAsString: true }` so both\n  parsers return unsafe integers as decimal strings.\n- Verified equivalent serialized results before timing every workload.\n- Measured the warmed-up `parse` hot path only. Module loading, WASM\n  instantiation, and unrelated startup or background activity were excluded.\n- Warmed up each implementation for 300 ms per workload.\n- Collected seven trials per implementation, with each trial running for at\n  least 750 ms.\n- Alternated implementation order between trials to reduce bias from CPU\n  temperature and dynamic frequency scaling.\n- Requested garbage collection before every measured trial.\n- Reported the median of seven trials rather than the single best result.\n- Calculated the speedup as `RS ops/s / original ops/s`.\n- Excluded `stringify` because the two packages use different output semantics\n  for native JavaScript `BigInt` values.\n\nTest environment: August 28, 2026; Apple M3 (8-core); 16 GB RAM; macOS arm64;\nNode.js v24.18.0.\n\n### Results\n\n| Workload | JSON size | Original ops/s | RS ops/s | Original MB/s | RS MB/s | Speedup | Throughput increase |\n| --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: |\n| Safe integers, small document | 1021 B | 29,898 | 85,412 | 30.5 | 87.2 | 2.86x | 185.7% |\n| Unsafe integers, small document | 1.3 KiB | 21,109 | 60,709 | 28.9 | 83.2 | 2.88x | 187.6% |\n| Mixed integers, medium document | 114.0 KiB | 282 | 894 | 33.0 | 104.5 | 3.17x | 216.7% |\n| Unsafe integers, medium document | 141.4 KiB | 201 | 793 | 29.1 | 114.8 | 3.95x | 294.8% |\n| Unsafe integers, large document | 1.42 MiB | 18 | 79 | 26.6 | 118.0 | 4.44x | 343.6% |\n\nBenchmark results depend on CPU architecture, Node.js version, system load, and\nJSON structure. These measurements describe the environment above and do not\nguarantee the same performance ratio on every system.\n\n\n\n## Installation\n\n```bash\nnpm install json-bigint-rs\n```\n\nRequires Node.js 22.19.0 or later.\n\n## Usage\n\n### Parse API responses containing large integer identifiers\n\n```js\nconst JSONBig = require('json-bigint-rs');\n\nconst data = JSONBig.parse(`{\n  \"userId\": 9223372036854775807,\n  \"orderId\": 18446744073709551615,\n  \"count\": 42\n}`);\n\nconsole.log(data.userId);  // '9223372036854775807'\nconsole.log(data.orderId); // '18446744073709551615'\nconsole.log(data.count);   // 42\n```\n\nIntegers within the safe range remain JavaScript `number` values. Only integer\ntokens outside that range are converted to strings.\n\n### Convert selected fields to native BigInt\n\n`parse` accepts the same `reviver` argument as native `JSON.parse`:\n\n```js\nconst JSONBig = require('json-bigint-rs');\n\nconst data = JSONBig.parse(\n  '{\"userId\":9223372036854775807,\"name\":\"Ada\"}',\n  (key, value) => (key === 'userId' ? BigInt(value) : value),\n);\n\nconsole.log(data.userId);        // 9223372036854775807n\nconsole.log(typeof data.userId); // 'bigint'\n```\n\n### Serialize objects containing BigInt values\n\nNative `JSON.stringify` cannot serialize `BigInt` values directly.\n`json-bigint-rs` encodes them as exact decimal JSON strings:\n\n```js\nconst JSONBig = require('json-bigint-rs');\n\nconst json = JSONBig.stringify({\n  userId: 9223372036854775807n,\n  amount: 100n,\n});\n\nconsole.log(json);\n// {\"userId\":\"9223372036854775807\",\"amount\":\"100\"}\n```\n\n### Use a replacer and formatted output\n\n`stringify` supports the native `JSON.stringify` `replacer` and `space`\narguments:\n\n```js\nconst JSONBig = require('json-bigint-rs');\n\nconst json = JSONBig.stringify(\n  { userId: 9223372036854775807n, internal: true },\n  (key, value) => (key === 'internal' ? undefined : value),\n  2,\n);\n\nconsole.log(json);\n// {\n//   \"userId\": \"9223372036854775807\"\n// }\n```\n\n## Parsing behavior\n\n- Integers from `-9007199254740991` through `9007199254740991` remain `number`\n  values.\n- Integers outside that range become exact decimal strings.\n- Positive and negative integers of arbitrary textual length are supported.\n- Numeric text already inside a JSON string is left unchanged.\n- Decimal and exponent notation continue to use native V8 `Number` semantics.\n- Invalid JSON remains invalid and throws a `SyntaxError`.\n\n## API\n\n```ts\nparse(text: string, reviver?: Reviver): unknown\n\nstringify(\n  value: unknown,\n  replacer?: Replacer,\n  space?: string | number,\n): string | undefined\n```\n","readmeFilename":"README.md"}