{"name":"json-web3","version":"1.0.2","keywords":["json","bigint","arraybuffer","serialization","deserialization","web3"],"author":{"name":"haozi"},"license":"MIT","_id":"json-web3@1.0.2","maintainers":[{"name":"haozime","email":"syntaxright@gmail.com"}],"homepage":"https://github.com/haozi/json-web3#readme","bugs":{"url":"https://github.com/haozi/json-web3/issues"},"dist":{"shasum":"b346528749713808afadee3d5461fe896b9581cb","tarball":"http://registry-npm.ywwl.com/json-web3/download/json-web3-1.0.2.tgz","fileCount":9,"integrity":"sha512-eBA6k6sudlA92O0EZg+Q5I0tabnur8/h6A/Keop6zfFLVVaSBDngwjVm2/HhRFJGpYwUVyOoL6HjiuJwHs1LVQ==","signatures":[{"sig":"MEQCIEnZL7wMDSxZHWiH6OJthwLd5I55v991wHHF7ZberMATAiBbBYMM7II9+J2t4WiudGhw07iVmaRuaEirQ4HfC5Z5Sg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":40367,"size":6849,"noattachment":false,"key":"/json-web3/-/json-web3-1.0.2.tgz"},"main":"./dist/index.cjs","type":"module","_from":"file:json-web3-1.0.2.tgz","types":"./dist/index.d.ts","module":"./dist/index.js","engines":{"node":">=18"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"}},"scripts":{"lint":"prettier . --write","test":"vitest run --coverage","build":"tsup","test:watch":"vitest"},"_npmUser":{"name":"haozime","email":"syntaxright@gmail.com"},"_resolved":"/private/var/folders/6v/347fgvv55r98rd1g1y8n_zzc0000gp/T/f1ada7548b4dab1d082859f5962140c0/json-web3-1.0.2.tgz","_integrity":"sha512-eBA6k6sudlA92O0EZg+Q5I0tabnur8/h6A/Keop6zfFLVVaSBDngwjVm2/HhRFJGpYwUVyOoL6HjiuJwHs1LVQ==","repository":{"url":"git+https://github.com/haozi/json-web3.git","type":"git"},"_npmVersion":"11.6.2","description":"BigInt-safe JSON serialization and deserialization for Web3 use cases.","directories":{},"sideEffects":false,"_nodeVersion":"25.3.0","_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.5.1","vitest":"^4.0.17","prettier":"^3.8.0","typescript":"^5.9.3","@types/node":"^25.0.9","@vitest/coverage-v8":"^4.0.17","prettier-plugin-lint-md":"^1.0.1","prettier-plugin-sort-json":"^4.2.0","prettier-plugin-tailwindcss":"^0.7.2","prettier-plugin-organize-imports":"^4.3.0"},"_npmOperationalInternal":{"tmp":"tmp/json-web3_1.0.2_1768881294666_0.30772833541188316","host":"s3://npm-registry-packages-npm-production"},"readme":"# json-web3\n\n[![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/haozi/json-web3/deploy.yml)](https://github.com/haozi/json-web3/actions)\n[![npm](https://img.shields.io/npm/v/json-web3.svg)](https://www.npmjs.com/package/json-web3)\n[![codecov](https://codecov.io/gh/haozi/json-web3/branch/main/graph/badge.svg)](https://app.codecov.io/gh/haozi/json-web3)\n[![contributors](https://img.shields.io/github/contributors/haozi/json-web3)](https://github.com/haozi/json-web3/graphs/contributors)\n[![LICENSE](https://img.shields.io/npm/l/json-web3)](https://github.com/haozi/json-web3/blob/main/LICENSE)\n[![Size](https://img.shields.io/bundlejs/size/json-web3.svg)](https://cdn.jsdelivr.net/npm/json-web3/+esm)\n\nBigInt-safe JSON serialization and deserialization for Web3 data.\n\n## Install\n\n```bash\npnpm add json-web3\n# or\nnpm i json-web3\n# or\nyarn add json-web3\n```\n\n## Usage\n\n```ts\nimport jsonWeb3 from 'json-web3'\n\nconst payload = {\n  balance: 1234567890123456789n,\n  decimals: 18n,\n  u8Array: new Uint8Array([1, 2, 3, 255]),\n  u16Array: new Uint16Array([1, 2, 3, 255]),\n  bigIntArray: new BigInt64Array([18446744073709551615n, 2n, 3n, 255n]),\n  createdAt: new Date('2020-01-02T03:04:05.006Z'),\n  ids: new Set([123, 456]),\n  headers: new Map([['hello', 'world']]),\n  re: /([^\\s]+)/g,\n  url: new URL('https://example.com/'),\n  fn: function echo(arg) {\n    return arg\n  },\n}\n\nconst text = jsonWeb3.stringify(payload)\n// => {\"balance\":{\"__@json.bigint__\":\"1234567890123456789\"},\"decimals\":{\"__@json.bigint__\":\"18\"},\"u8Array\":{\"__@json.typedarray__\":{\"type\":\"Uint8Array\",\"bytes\":\"0x010203ff\"}},\"u16Array\":{\"__@json.typedarray__\":{\"type\":\"Uint16Array\",\"bytes\":\"0x010002000300ff00\"}},\"bigIntArray\":{\"__@json.typedarray__\":{\"type\":\"BigInt64Array\",\"bytes\":\"0xffffffffffffffff02000000000000000300000000000000ff00000000000000\"}}}\n\nconst restored = jsonWeb3.parse(text)\n/* =>\n  {\n    balance: 1234567890123456789n,\n    decimals: 18n,\n    u8Array: Uint8Array(4) [1, 2, 3, 255]...,\n    u16Array: Uint16Array(4)...,\n    bigIntArray: BigInt64Array(4)...,\n    createdAt: Date(...),\n    ids: Set(2) {...},\n    headers: Map(1) {...},\n    re: /([^\\s]+)/g,\n    url: URL(...),\n    fn: undefined\n  }\n*/\n\nconst textUnsafe = jsonWeb3.stringify_UNSAFE(payload)\nconst restoredUnsafe = jsonWeb3.parse_UNSAFE(textUnsafe)\n// restoredUnsafe.fn is a callable function\n```\n\n## Full example\n\n```ts\nimport jsonWeb3 from 'json-web3'\n\nwindow.JSON = jsonWeb3 // Yes, you can replace it directly; it is fully compatible.\n```\n\n## API (Fully compatible with native globalThis.JSON)\n\n- `stringify(value, replacer?, space?)`\n- `parse(text, reviver?)`\n- `stringify_UNSAFE(value, replacer?, space?)` (serializes `Function` payloads)\n- `parse_UNSAFE(text, reviver?)` (revives `Function` payloads via `new Function(...)`)\n\n## Type support\n\n| type                | supported by standard JSON? | supported by json-web3?               |\n| ------------------- | --------------------------- | ------------------------------------- |\n| `string`            | ✅                          | ✅                                    |\n| `number`            | ✅                          | ✅                                    |\n| `boolean`           | ✅                          | ✅                                    |\n| `null`              | ✅                          | ✅                                    |\n| `Array`             | ✅                          | ✅                                    |\n| `Object`            | ✅                          | ✅                                    |\n| `undefined`         | ❌                          | ❌                                    |\n| `Infinity`          | ❌                          | ✅                                    |\n| `-Infinity`         | ❌                          | ✅                                    |\n| `NaN`               | ❌                          | ✅                                    |\n| `BigInt`            | ❌                          | ✅                                    |\n| `Date`              | ❌                          | ✅                                    |\n| `RegExp`            | ❌                          | ✅                                    |\n| `Set`               | ❌                          | ✅                                    |\n| `Map`               | ❌                          | ✅                                    |\n| `URL`               | ❌                          | ✅                                    |\n| `ArrayBuffer`       | ❌                          | ✅                                    |\n| `Uint8Array`        | ❌                          | ✅                                    |\n| `Uint8ClampedArray` | ❌                          | ✅                                    |\n| `Uint16Array`       | ❌                          | ✅                                    |\n| `Uint32Array`       | ❌                          | ✅                                    |\n| `Int8Array`         | ❌                          | ✅                                    |\n| `Int16Array`        | ❌                          | ✅                                    |\n| `Int32Array`        | ❌                          | ✅                                    |\n| `Float16Array`      | ❌                          | ✅                                    |\n| `Float32Array`      | ❌                          | ✅                                    |\n| `Float64Array`      | ❌                          | ✅                                    |\n| `BigInt64Array`     | ❌                          | ✅                                    |\n| `BigUint64Array`    | ❌                          | ✅                                    |\n| `Function`          | ❌                          | ✅ ⚠️(use UNSAFE api, it's dangerous) |\n\n## Note\n\n- `bigint` values are encoded as objects: `{\"__@json.bigint__\":\"<value>\"}`.\n- Non-finite numbers (`NaN`, `Infinity`, `-Infinity`) are encoded as `{\"__@json.number__\":\"<value>\"}`.\n- `Date` values are encoded as `{\"__@json.date__\":<timestamp>}`.\n- `Map` values are encoded as `{\"__@json.map__\":[[k,v],...]}` and `Set` values as `{\"__@json.set__\":[...]}`.\n- `RegExp` values are encoded as `{\"__@json.regexp__\":{\"source\":\"...\",\"flags\":\"...\"}}`.\n- `URL` values are encoded as `{\"__@json.url__\":\"...\"}`.\n- `Function` values are encoded as `{\"__@json.function__\":\"<source>\"}` by `stringify_UNSAFE` and are only revived by `parse_UNSAFE` using `new Function(...)` (using the UNSAFE function pair is dangerous; make sure your data is trusted).\n- `ArrayBuffer` values are encoded as `{\"__@json.arraybuffer__\":{\"bytes\":\"0x...\"}}` and decoded back to `ArrayBuffer`.\n- Node `Buffer` JSON shapes and typed arrays are encoded as `{\"__@json.typedarray__\":{\"type\":\"<Name>\",\"bytes\":\"0x...\"}}` and decoded back to the original typed array (`Uint8Array`, `Uint8ClampedArray`, `Uint16Array`, `Uint32Array`, `Int8Array`, `Int16Array`, `Int32Array`, `Float32Array`, `Float64Array`, `BigInt64Array`, `BigUint64Array`).\n\nCompared to libraries that require eval-based parsing (for example, `serialize-javascript`), this approach is generally safer and more efficient.\n\n## RFC (Serialization Format)\n\nTo enable cross-language interoperability, the serialization format is specified\nin [RFC.md](RFC.md). It defines the canonical tag objects, payload shapes, validation\nrules, and UNSAFE function handling.\n","publish_time":1768881294802,"_cnpm_publish_time":1768881294802,"dist-tags":{"latest":"1.3.5"}}