{"_id":"parse-json-stream","_rev":"33-a2394e76e1ce2c92852bf5eedea7cc4d","name":"parse-json-stream","dist-tags":{"latest":"3.2.0"},"versions":{"3.0.0":{"name":"parse-json-stream","version":"3.0.0","keywords":["json","stream","parser","streaming","llm","real-time","progressive","async","generator","typescript"],"author":{"name":"Tomaj Bayat"},"license":"ISC","_id":"parse-json-stream@3.0.0","maintainers":[{"name":"btomaj","email":"hello@tomaj.co"}],"homepage":"https://github.com/btomaj/parse-json-stream#readme","bugs":{"url":"https://github.com/btomaj/parse-json-stream/issues"},"dist":{"shasum":"7b558b86f766c8e7073a0bcd89e8db8bc9519729","tarball":"https://registry.npmjs.org/parse-json-stream/-/parse-json-stream-3.0.0.tgz","fileCount":18,"integrity":"sha512-3CXhiUak/WG+3y2JhOtxQvQqjV1/DtFRMMDxWsMiU6KAWsaX9h/6UCwgvOKFkQMwscyq8v1uX790KJuxravwXA==","signatures":[{"sig":"MEUCIQCtzojnb4KIgPvfpi/BQqfrDucmQs5n0GbyEaXgYu69kgIgAwMV6mVReyYTdoYkeVd04K42NruS+IcvaktffBjrd4g=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":94717},"main":"./dist/index.js","types":"./dist/index.d.ts","engines":{"node":">=16.0.0"},"exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"./patch":{"types":"./dist/patch.d.ts","default":"./dist/patch.js"}},"gitHead":"b899b56c6412c8fb9e60b8b6e1ce9cb6395fa9d3","scripts":{"pack":"npm pack && tar -tzf *.tgz","test":"NODE_OPTIONS=--experimental-eventsource vitest run","build":"tsc && tsc-alias","format":"biome check --write","typecheck":"tsc --noEmit"},"_npmUser":{"name":"btomaj","email":"hello@tomaj.co"},"repository":{"url":"git+https://github.com/btomaj/parse-json-stream.git","type":"git"},"_npmVersion":"10.9.2","description":"High-performance, real-time, JSON stream parser that yields partial values as they arrive from a stream. Perfect for parsing JSON from LLMs and displaying values immediately.","directories":{},"_nodeVersion":"22.14.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"packageManager":"pnpm@10.15.0+sha512.486ebc259d3e999a4e8691ce03b5cac4a71cbeca39372a9b762cb500cfdf0873e2cb16abe3d951b1ee2cf012503f027b98b6584e4df22524e0c7450d9ec7aa7b","devDependencies":{"vitest":"^3.1.4","tsc-alias":"^1.8.16","typescript":"^5.8.3","@types/node":"^22.15.29","@biomejs/biome":"^2.0.0","@vitest/coverage-v8":"3.1.4","vite-tsconfig-paths":"^5.1.4"},"_npmOperationalInternal":{"tmp":"tmp/parse-json-stream_3.0.0_1755861686896_0.9325960817826742","host":"s3://npm-registry-packages-npm-production"}},"3.1.1":{"name":"parse-json-stream","version":"3.1.1","keywords":["json","stream","parser","streaming","llm","real-time","progressive","async","generator","typescript"],"author":{"name":"Tomaj Bayat"},"license":"ISC","_id":"parse-json-stream@3.1.1","maintainers":[{"name":"btomaj","email":"hello@tomaj.co"}],"homepage":"https://github.com/btomaj/parse-json-stream#readme","bugs":{"url":"https://github.com/btomaj/parse-json-stream/issues"},"dist":{"shasum":"f1f6f3152a9404399417c56d61405815d9a46fe8","tarball":"https://registry.npmjs.org/parse-json-stream/-/parse-json-stream-3.1.1.tgz","fileCount":20,"integrity":"sha512-6MqnVo+U3KaKrM0tDGUIqAp7MTPVC8AENDUBtYzIcLRb0eqgB0nb8jQPPxYFskmNuHl2xHnfzIZQJ5bKqHSDKg==","signatures":[{"sig":"MEUCIQDAUDhZv8AlkaGl9lJGxFBYv1LyWPqRFdkFWXvcAMLfKQIgGKIg5u+Pm4qAH2Vhx5Z8DWkTb+WH7TlUfQZuI2m//TQ=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":149571},"main":"./dist/index.js","_from":"file:parse-json-stream-3.1.1.tgz","types":"./dist/index.d.ts","engines":{"node":">=16.0.0"},"exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"./patch":{"types":"./dist/patch.d.ts","default":"./dist/patch.js"},"./react":{"types":"./dist/use-json-stream.d.ts","default":"./dist/use-json-stream.js"}},"scripts":{"pack":"npm pack && tar -tzf *.tgz","test":"NODE_OPTIONS=--experimental-eventsource vitest run","build":"tsc && tsc-alias","format":"biome check --write","typecheck":"tsc --noEmit"},"_npmUser":{"name":"btomaj","email":"hello@tomaj.co"},"_resolved":"/tmp/6b24a39e2852f80092411f8e026e761a/parse-json-stream-3.1.1.tgz","_integrity":"sha512-6MqnVo+U3KaKrM0tDGUIqAp7MTPVC8AENDUBtYzIcLRb0eqgB0nb8jQPPxYFskmNuHl2xHnfzIZQJ5bKqHSDKg==","repository":{"url":"git+https://github.com/btomaj/parse-json-stream.git","type":"git"},"_npmVersion":"10.9.2","description":"High-performance, real-time, JSON stream parser that yields partial values as they arrive from a stream. Perfect for parsing JSON from LLMs and displaying values immediately.","directories":{},"_nodeVersion":"22.14.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"msw":"^2.11.1","jsdom":"^26.1.0","react":"^19.1.1","vitest":"^3.1.4","tsc-alias":"^1.8.16","typescript":"^5.8.3","@types/node":"^22.15.29","@types/react":"^19.1.12","@biomejs/biome":"^2.0.0","@vitest/coverage-v8":"3.1.4","vite-tsconfig-paths":"^5.1.4","@testing-library/react":"^16.3.0"},"peerDependencies":{"react":"^19.1.1"},"_npmOperationalInternal":{"tmp":"tmp/parse-json-stream_3.1.1_1757505308312_0.9487710845772561","host":"s3://npm-registry-packages-npm-production"}},"3.1.2":{"name":"parse-json-stream","version":"3.1.2","keywords":["json","stream","parser","streaming","llm","real-time","progressive","async","generator","typescript"],"author":{"name":"Tomaj Bayat"},"license":"ISC","_id":"parse-json-stream@3.1.2","maintainers":[{"name":"btomaj","email":"hello@tomaj.co"}],"homepage":"https://github.com/btomaj/parse-json-stream#readme","bugs":{"url":"https://github.com/btomaj/parse-json-stream/issues"},"dist":{"shasum":"8b9cf75a4b398ce297e918d3348a5ba368641a17","tarball":"https://registry.npmjs.org/parse-json-stream/-/parse-json-stream-3.1.2.tgz","fileCount":20,"integrity":"sha512-BUO0EHvWEEJkLTSfCrD5PZf7y4U0hVX6+/CiP9gR9Q8uUX78v25MQ7KKeRGPUC5K9A0bThZf/08LBD+Q1pcwGA==","signatures":[{"sig":"MEYCIQCR3nrHVXeNfV/CM+e76u4AcuS3MqK9m8JzJyHLiCnoFwIhAO1rrWjJeGmzBTvz21qeeHEd3rj4wG4Kb2ju2qQ/DnZr","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":149572},"main":"./dist/index.js","_from":"file:parse-json-stream-3.1.2.tgz","types":"./dist/index.d.ts","engines":{"node":">=16.0.0"},"exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"./patch":{"types":"./dist/patch.d.ts","default":"./dist/patch.js"},"./react":{"types":"./dist/use-json-stream.d.ts","default":"./dist/use-json-stream.js"}},"scripts":{"pack":"npm pack && tar -tzf *.tgz","test":"NODE_OPTIONS=--experimental-eventsource vitest run","build":"tsc && tsc-alias","format":"biome check --write","typecheck":"tsc --noEmit"},"_npmUser":{"name":"btomaj","email":"hello@tomaj.co"},"_resolved":"/tmp/54f4ba11080db81f36afbea93b4cdbdd/parse-json-stream-3.1.2.tgz","_integrity":"sha512-BUO0EHvWEEJkLTSfCrD5PZf7y4U0hVX6+/CiP9gR9Q8uUX78v25MQ7KKeRGPUC5K9A0bThZf/08LBD+Q1pcwGA==","repository":{"url":"git+https://github.com/btomaj/parse-json-stream.git","type":"git"},"_npmVersion":"10.9.2","description":"High-performance, real-time, JSON stream parser that yields partial values as they arrive from a stream. Perfect for parsing JSON from LLMs and displaying values immediately.","directories":{},"_nodeVersion":"22.14.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"msw":"^2.11.1","jsdom":"^26.1.0","react":"^19.1.1","vitest":"^3.1.4","tsc-alias":"^1.8.16","typescript":"^5.8.3","@types/node":"^22.15.29","@types/react":"^19.1.12","@biomejs/biome":"^2.0.0","@vitest/coverage-v8":"3.1.4","vite-tsconfig-paths":"^5.1.4","@testing-library/react":"^16.3.0"},"peerDependencies":{"react":">=16.8.0"},"_npmOperationalInternal":{"tmp":"tmp/parse-json-stream_3.1.2_1757505652893_0.2054144101057116","host":"s3://npm-registry-packages-npm-production"}},"3.1.3":{"name":"parse-json-stream","version":"3.1.3","keywords":["json","stream","parser","streaming","llm","real-time","progressive","async","generator","typescript"],"author":{"name":"Tomaj Bayat"},"license":"ISC","_id":"parse-json-stream@3.1.3","maintainers":[{"name":"btomaj","email":"hello@tomaj.co"}],"homepage":"https://github.com/btomaj/parse-json-stream#readme","bugs":{"url":"https://github.com/btomaj/parse-json-stream/issues"},"dist":{"shasum":"c395d377e40b55dac0eea08f8d7d1bd15c592889","tarball":"https://registry.npmjs.org/parse-json-stream/-/parse-json-stream-3.1.3.tgz","fileCount":20,"integrity":"sha512-b97LbYDIfMmUOI9biRzI14RVHBOSm3UZiqxd9338UW8eOgzDC5qpFpSFubcPkpSJOHfD4ID5cEwBrRUhFMrW7Q==","signatures":[{"sig":"MEQCIHZUCi9hnAu8RDFIfjdjKnuvs9lIR562UsP5w3YdvmA+AiBpuYEeChl40GdYZXSvzSfMUuxjkeBvW13B4nKtIC8gNg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":149685},"main":"./dist/index.js","_from":"file:parse-json-stream-3.1.3.tgz","types":"./dist/index.d.ts","engines":{"node":">=16.0.0"},"exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"./patch":{"types":"./dist/patch.d.ts","default":"./dist/patch.js"},"./react":{"types":"./dist/use-json-stream.d.ts","default":"./dist/use-json-stream.js"}},"scripts":{"pack":"npm pack && tar -tzf *.tgz","test":"NODE_OPTIONS=--experimental-eventsource vitest run","build":"tsc && tsc-alias","format":"biome check --write","typecheck":"tsc --noEmit"},"_npmUser":{"name":"btomaj","email":"hello@tomaj.co"},"_resolved":"/tmp/ff952de4960c86463beabf4d2a373f4e/parse-json-stream-3.1.3.tgz","_integrity":"sha512-b97LbYDIfMmUOI9biRzI14RVHBOSm3UZiqxd9338UW8eOgzDC5qpFpSFubcPkpSJOHfD4ID5cEwBrRUhFMrW7Q==","repository":{"url":"git+https://github.com/btomaj/parse-json-stream.git","type":"git"},"_npmVersion":"10.9.2","description":"High-performance, real-time, JSON stream parser that yields partial values as they arrive from a stream. Perfect for parsing JSON from LLMs and displaying values immediately.","directories":{},"_nodeVersion":"22.14.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"msw":"^2.11.1","jsdom":"^26.1.0","react":"^19.1.1","vitest":"^3.1.4","tsc-alias":"^1.8.16","typescript":"^5.8.3","@types/node":"^22.15.29","@types/react":"^19.1.12","@biomejs/biome":"^2.0.0","@vitest/coverage-v8":"3.1.4","vite-tsconfig-paths":"^5.1.4","@testing-library/react":"^16.3.0"},"peerDependencies":{"react":">=16.8.0"},"_npmOperationalInternal":{"tmp":"tmp/parse-json-stream_3.1.3_1757505933624_0.24227229402593697","host":"s3://npm-registry-packages-npm-production"}},"3.1.7":{"name":"parse-json-stream","version":"3.1.7","keywords":["json","stream","parser","streaming","llm","real-time","progressive","async","generator","typescript"],"author":{"name":"Tomaj Bayat"},"license":"ISC","_id":"parse-json-stream@3.1.7","maintainers":[{"name":"btomaj","email":"hello@tomaj.co"}],"homepage":"https://github.com/btomaj/parse-json-stream#readme","bugs":{"url":"https://github.com/btomaj/parse-json-stream/issues"},"dist":{"shasum":"3f42c36320e8236ee376982870671cd5c0a30832","tarball":"https://registry.npmjs.org/parse-json-stream/-/parse-json-stream-3.1.7.tgz","fileCount":20,"integrity":"sha512-wrAF1Z2HRvR1Knj+k5S75tKNmDeY8l5ofhy9wVWSZqPGEFAFlCibWBXkiwav0jWoNkN3vAvoxexaAd3Y9875mA==","signatures":[{"sig":"MEQCICWZNuA8KDcap+H0lHWzr10ZSbnTeDC7TWgkBPAwQqQmAiAnHrkQEIil6YbjHotNW0kRz/0cElf59+yeVDgjq13FrA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/parse-json-stream@3.1.7","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":150759},"main":"./dist/index.js","_from":"file:parse-json-stream-3.1.7.tgz","types":"./dist/index.d.ts","engines":{"node":">=16.0.0"},"exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"./patch":{"types":"./dist/patch.d.ts","default":"./dist/patch.js"},"./react":{"types":"./dist/use-json-stream.d.ts","default":"./dist/use-json-stream.js"}},"scripts":{"pack":"npm pack && tar -tzf *.tgz","test":"NODE_OPTIONS=--experimental-eventsource vitest run","build":"tsc && tsc-alias","format":"biome check --write","typecheck":"tsc --noEmit"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:ec88bee1-98fa-4b08-965e-b51697326f3d"}},"_resolved":"/tmp/89b7a0abe4b3dc088aaeb067f3d271ef/parse-json-stream-3.1.7.tgz","_integrity":"sha512-wrAF1Z2HRvR1Knj+k5S75tKNmDeY8l5ofhy9wVWSZqPGEFAFlCibWBXkiwav0jWoNkN3vAvoxexaAd3Y9875mA==","repository":{"url":"git+https://github.com/btomaj/parse-json-stream.git","type":"git"},"_npmVersion":"11.12.0","description":"High-performance, real-time, JSON stream parser that yields partial values as they arrive from a stream. Perfect for parsing JSON from LLMs and displaying values immediately.","directories":{},"_nodeVersion":"22.14.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"msw":"^2.11.1","jsdom":"^26.1.0","react":"^19.1.1","vitest":"^3.1.4","tsc-alias":"^1.8.16","typescript":"^5.8.3","@types/node":"^22.15.29","@types/react":"^19.1.12","@biomejs/biome":"^2.0.0","@vitest/coverage-v8":"3.1.4","vite-tsconfig-paths":"^5.1.4","@testing-library/react":"^16.3.0"},"peerDependencies":{"react":">=16.8.0"},"_npmOperationalInternal":{"tmp":"tmp/parse-json-stream_3.1.7_1774221704320_0.22911908989957097","host":"s3://npm-registry-packages-npm-production"}},"3.2.0":{"_id":"parse-json-stream@3.2.0","bugs":{"url":"https://github.com/btomaj/parse-json-stream/issues"},"dist":{"shasum":"dc74c690cc7cfdd818196dee9a24c532e3bf65f1","tarball":"https://registry.npmjs.org/parse-json-stream/-/parse-json-stream-3.2.0.tgz","fileCount":20,"integrity":"sha512-F+KPiFQiXrquAn8bTSjVVaftyhPnV6ma6TGX3JVQdcc0/WTJyiPDXLBdECXxm1CFVmG9tEFZSC2w8ZbzPlwypA==","signatures":[{"sig":"MEQCIHhyN6to2YMxvWQDCZYyCwuBs8QsSdM0fLoZoQCrt89oAiA9aUhL96eqhVDr05MFA1fGAm8Y0vC2p9zv14DiLDb2qA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDI/iHG/pBwHQcNqYTVJLvysMYy3O9UQJcbaBqknYkowgIhANNDeTwdIHQDcEqDcdPReJLuuQ4gS/nbwLoL7BjNJ3zU"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/parse-json-stream@3.2.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":150091},"main":"./dist/index.js","name":"parse-json-stream","types":"./dist/index.d.ts","author":{"name":"Tomaj Bayat"},"engines":{"node":">=16.0.0"},"exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"./patch":{"types":"./dist/patch.d.ts","default":"./dist/patch.js"},"./react":{"types":"./dist/use-json-stream.d.ts","default":"./dist/use-json-stream.js"}},"gitHead":"28ab8fe5866ea9b3eac4b55fdd7e56b866fdb951","license":"ISC","scripts":{"test":"NODE_OPTIONS=--experimental-eventsource vitest run","build":"rm -rf dist && tsc","format":"biome check --write","prepack":"nub run build","typecheck":"tsc --noEmit"},"version":"3.2.0","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:9917b099-986e-4879-9931-0dbb390cc453"}},"homepage":"https://github.com/btomaj/parse-json-stream#readme","keywords":["json","stream","parser","streaming","llm","real-time","progressive","async","generator","typescript"],"devEngines":{"packageManager":{"name":"nub","onFail":"warn","version":"^0.4.7"}},"repository":{"url":"git+https://github.com/btomaj/parse-json-stream.git","type":"git"},"_npmVersion":"11.19.0","allowBuilds":{"msw":true,"esbuild":true,"@biomejs/biome":true},"description":"High-performance, real-time, JSON stream parser that yields partial values as they arrive from a stream. Perfect for parsing JSON from LLMs and displaying values immediately.","directories":{},"maintainers":[{"name":"btomaj","email":"hello@tomaj.co"}],"_nodeVersion":"24.21.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"msw":"^2.11.1","jsdom":"^26.1.0","react":"^19.1.1","vitest":"4.1.11","typescript":"^5.8.3","@types/node":"^22.15.29","@types/react":"^19.1.12","@biomejs/biome":"^2.0.0","keep-a-changelog":"^3.2.0","semantic-release":"^25.0.9","@vitest/coverage-v8":"4.1.11","@semantic-release/git":"^11.0.1","@semantic-release/exec":"^7.1.0","@testing-library/react":"^16.3.0"},"peerDependencies":{"react":">=16.8.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/parse-json-stream_3.2.0_1789371160003_0.360496838041964"}}},"time":{"created":"2025-08-22T11:21:26.789Z","modified":"2026-09-14T07:32:40.412Z","1.0.0":"2018-05-27T23:48:38.471Z","2.0.0":"2018-05-31T20:17:32.076Z","2.0.1":"2018-06-09T15:13:54.914Z","2.0.2":"2018-09-14T18:13:49.561Z","2.0.3":"2018-11-05T17:35:56.329Z","2.0.4":"2019-01-15T16:32:47.761Z","2.0.5":"2019-01-18T13:01:37.400Z","2.0.6":"2019-06-19T00:14:31.407Z","2.1.0":"2020-07-10T23:01:55.510Z","2.1.1":"2020-07-10T23:13:52.262Z","2.1.2":"2020-07-11T19:01:02.406Z","2.2.0":"2020-07-12T20:02:21.115Z","2.2.1":"2020-07-12T20:38:10.579Z","2.2.2":"2021-02-05T19:09:50.568Z","2.2.3":"2021-02-20T10:38:49.330Z","2.2.4":"2021-02-28T07:11:20.330Z","2.2.5":"2021-02-28T07:16:42.142Z","2.3.0":"2022-02-27T08:01:08.438Z","2.4.0":"2022-02-28T07:00:25.083Z","3.0.0":"2025-08-22T11:21:27.089Z","3.1.0":"2025-09-10T11:22:09.725Z","3.1.1":"2025-09-10T11:55:08.511Z","3.1.2":"2025-09-10T12:00:53.076Z","3.1.3":"2025-09-10T12:05:33.828Z","3.1.7":"2026-03-22T23:21:44.452Z","3.2.0":"2026-09-14T07:32:40.095Z"},"bugs":{"url":"https://github.com/btomaj/parse-json-stream/issues"},"author":{"name":"Tomaj Bayat"},"license":"ISC","homepage":"https://github.com/btomaj/parse-json-stream#readme","keywords":["json","stream","parser","streaming","llm","real-time","progressive","async","generator","typescript"],"repository":{"url":"git+https://github.com/btomaj/parse-json-stream.git","type":"git"},"description":"High-performance, real-time, JSON stream parser that yields partial values as they arrive from a stream. Perfect for parsing JSON from LLMs and displaying values immediately.","maintainers":[{"name":"btomaj","email":"hello@tomaj.co"}],"readme":"# parse-json-stream\n\n[![npm version](https://badge.fury.io/js/parse-json-stream.svg)](https://badge.fury.io/js/parse-json-stream)\n[![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue.svg)](https://www.typescriptlang.org/)\n[![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg)](https://opensource.org/licenses/ISC)\n\nHigh-performance stream parser that parses and yields incomplete JSON values as they arrive from a stream. \n\n## Installation\n\n```bash\nnpm install parse-json-stream\n```\n\n## Quick start\n\n```typescript\nimport { parseStream } from \"parse-json-stream\";\n\nconst response = await fetch(\"/api/data\");\nif (!response.body) {\n  throw new Error(\"The response has no body\");\n}\n\nfor await (const chunk of parseStream(response.body)) {\n  console.log(chunk.value);   // Current part of the value\n  console.log(chunk.segments); // [\"users\", 0, \"name\"]\n  console.log(chunk.path);    // \"$.users[0].name\"\n  console.log(chunk.pointer); // \"/users/0/name\"\n  console.log(chunk.type);    // \"string\"\n}\n```\n\n`chunk.value` is a string fragment. A value can produce multiple chunks with the same path. Append these fragments to reconstruct the complete value.\n\n## Reference\n\n### `parseStream(stream, init?)`\n\nParses a supported stream and returns an `AsyncGenerator<JSONChunk>` that yields parsed chunks.\n\n- `stream`: The stream to parse.\n- `init.signal`: An optional `AbortSignal` that stops parsing.\n\n`parseStream` accepts:\n\n- `ReadableStream`\n- `WebSocket`\n- `EventSource`\n- `AsyncIterable<string | Uint8Array | ArrayBuffer>`\n\nStream data can contain strings, `Uint8Array` values, or `ArrayBuffer` values.\n\n### `JSONChunk`\n\n```typescript\ninterface JSONChunk {\n  readonly value: string;\n  readonly type: \"string\" | \"number\" | \"boolean\" | \"null\";\n  readonly segments: Array<string | number>;\n  readonly path: string;\n  readonly pointer: string;\n}\n```\n\n- `value` contains the current string fragment.\n- `type` contains the JSON value type.\n- `segments` contains object keys and array indexes.\n- `path` contains the JSONPath location, such as `$.users[0].name`.\n- `pointer` contains the JSON Pointer location, such as `/users/0/name`.\n\n## React\n\nImport `useJSONStream` from `parse-json-stream/react`.\n\n### `useJSONStream(bufferProcessor)`\n\nBuffers parsed chunks until the next browser animation frame, then calls `bufferProcessor` with this type:\n\n```typescript\n(chunks: Array<JSONChunk>) => void\n```\n\nThe callback can run more than once for a stream. Each call contains only the new chunks collected since the previous call. If React renders the component with a new callback, the next batch goes to the new callback.\n\n`useJSONStream` returns:\n\n- `fetchJSONStream(url, options?)`: Fetches a web address and consumes its response stream. `options` accepts standard [`RequestInit`](https://developer.mozilla.org/en-US/docs/Web/API/RequestInit) fields, such as `method`, `headers`, and `body`, except `signal`.\n- `consumeJSONStream(stream, init?)`: Consumes a supported stream. `init.signal` is an optional `AbortSignal`.\n\n`fetchJSONStream` and `consumeJSONStream` do not change until the hook unmounts so that you can add them to React dependency arrays.\n\n`useJSONStream` processes one JSON stream at a time. Starting a new stream stops the current parser. Starting a new fetch also cancels the current fetch request. When the component unmounts, the hook stops all active work and discards buffered chunks that have not been processed.\n\n#### `fetchJSONStream`\n\n`fetchJSONStream` fetches a web address and consumes its response stream:\n\n```tsx\nimport { useEffect, useState } from \"react\";\nimport { useJSONStream } from \"parse-json-stream/react\";\n\nfunction FetchJSONStream() {\n  const [text, setText] = useState(\"\");\n\n  const { fetchJSONStream } = useJSONStream((chunks) => {\n    const nextText = chunks.map((chunk) => chunk.value).join(\"\");\n    setText((currentText) => currentText + nextText);\n  });\n\n  useEffect(() => {\n    fetchJSONStream(\"/api/data\").catch(console.error);\n  }, [fetchJSONStream]);\n\n  return <div>{text}</div>;\n}\n```\n\n#### `consumeJSONStream`\n\n`consumeJSONStream` consumes a stream that the component already has:\n\n```tsx\nimport { useEffect, useState } from \"react\";\nimport { useJSONStream } from \"parse-json-stream/react\";\n\nfunction ConsumeJSONStream({ stream }: { stream: ReadableStream }) {\n  const [text, setText] = useState(\"\");\n\n  const { consumeJSONStream } = useJSONStream((chunks) => {\n    const nextText = chunks.map((chunk) => chunk.value).join(\"\");\n    setText((currentText) => currentText + nextText);\n  });\n\n  useEffect(() => {\n    consumeJSONStream(stream).catch(console.error);\n  }, [consumeJSONStream, stream]);\n\n  return <div>{text}</div>;\n}\n```\n\n### Testing the React hook\n\n`useJSONStream` schedules `bufferProcessor` with `requestAnimationFrame`. A test that controls timers must run the pending animation-frame callback before it checks the received chunks.\n\n## Patch global JSON object\n\nImport `parse-json-stream/patch` to add `parseStream` to the global `JSON` object:\n\n```javascript\nimport \"parse-json-stream/patch\";\n\nfor await (const chunk of JSON.parseStream(stream)) {\n  console.log(chunk.value);\n}\n```\n\n## License\n\n[ISC](LICENSE) © 2024\n","readmeFilename":"README.md"}