jsonriver

jsonriver is a simple JS library that will parse JSON incrementally as it streams in, e.g. from a network request or a language model. It gives you a sequence of increasingly complete values.

jsonriver is small (~2.5KiB gzipped), fast, has no dependencies, and uses only standard features so it works without polyfills or bundling anywhere that supports modern JavaScript, including here in your browser.

It's fully spec-compliant, the final output is guaranteed to be the same as parsing with JSON.parse.

What use is a streaming parse? Let's see a couple of examples.

Example 1: Streaming JSON from a network request

Note: the network has been artificially slowed for this demo.

Posts

Example 2: Streaming JSON from a language model by asking it nicely

JSON is a common format for getting structured information out of a language model, and it takes long enough to generate that you can give a better user experience by handling it incrementally.