Live data from Hacker News

JSON River – Parse JSON incrementally as it streams in

github.com

51–60 of 101 posts

Re: JSON River – Parse JSON incrementally as it streams in

#52
I wrote something similar that can also produce JSON incrementally from other streaming data sources. It combines a streaming JSON parser with streaming strings and a streaming regex engine.

Concretely, it means I can call an LLM, wrap its output stream in a streaming string, and treat it like a regular string. No need for print loops, it’s all handled behind the scenes. I can chain transformations (joining strings, splitting them with regexes, capturing substrings, etc.) and serialize the results into JSON progressively, building lazy sequences or maps on the fly.

The benefit is that I can start processing and emitting structured data immediately, without waiting for the LLM’s full response. Filtered output can be shown to users as it arrives, with near-zero added latency (aside from regex lookaheads).

Re: JSON River – Parse JSON incrementally as it streams in

#53
post #51

"has no dependencies, and uses only standard features of JavaScript so it works in any JS environment." Then I see a Node style import and npm. When did Node/NPM stop being dependencies and become standardized by JavaScript? Where's my raw es6 module?

FWIW the import syntax is now part of standard JS, according to the ECMAScript 2026 specification:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

And node seems to be used only as a dev dependency, to test, benchmark and build/package the project. If you'd be inclined you can use the project's code as-is elsewhere, i.e. in the browser.

Re: JSON River – Parse JSON incrementally as it streams in

#54
post #51

"has no dependencies, and uses only standard features of JavaScript so it works in any JS environment." Then I see a Node style import and npm. When did Node/NPM stop being dependencies and become standardized by JavaScript? Where's my raw es6 module?

Bare module specifiers aren't just for Node! Deno and browsers support import maps e.g.

The library doesn't use any APIs beyond those in the JS standard, so I'm pretty confident it will work everywhere, but happy to publish in more places and run more tests. Any in particular that you'd like to see?

Re: JSON River – Parse JSON incrementally as it streams in

#56
post #54
post #51

"has no dependencies, and uses only standard features of JavaScript so it works in any JS environment." Then I see a Node style import and npm. When did Node/NPM stop being dependencies and become standardized by JavaScript? Where's my raw es6 module?

Bare module specifiers aren't just for Node! Deno and browsers support import maps e.g. The library doesn't use any APIs beyond those in the JS standard, so I'm pretty confident it will work everywhere, but happy to publish in more places and run more tests. Any in particular that you'd like to see?

Mostly unrelated, but does anyone know how are you supposed to make path-less module specifiers work for Node if you are not using npm but rather system-installed JS packages (Debian etc. install node-* packages into /usr/share/nodejs/)? With `require` it just works, but with `import` it errors and suggests passing the absolute path (even though it clearly knows what path ...).

For some reason everybody in the JS world takes "download and execute random software from the Internet" as the only way to do things.

Re: JSON River – Parse JSON incrementally as it streams in

#57
post #42

Earlier quoted context omitted.

For LLMs I recommend just doing NDJSON, that is, newline delimited json. It's much simpler to implement

Do any LLMs support constrained generation of newline delimited json? Or have you found that they're generally reliable enough that you don't need to do constrained sampling?

not for the standard hosted APIs using structured output or function calling, best you can get is an array

Re: JSON River – Parse JSON incrementally as it streams in

#58
post #56
post #54

Earlier quoted context omitted.

Bare module specifiers aren't just for Node! Deno and browsers support import maps e.g. The library doesn't use any APIs beyond those in the JS standard, so I'm pretty confident it will work everywhere, but happy to publish in more places and run more tests. Any in particular that you'd like to see?

Mostly unrelated, but does anyone know how are you supposed to make path-less module specifiers work for Node if you are not using npm but rather system-installed JS packages (Debian etc. install node-* packages into /usr/share/nodejs/)? With `require` it just works, but with `import` it errors and suggests passing the absolute path (even though it clearly knows what path ...). For some reason everybody in the JS wor…

Try import maps, something like:

    {
      "imports": {
        "express": "/usr/share/nodejs/express/index.js",
        "another-module": "/usr/share/nodejs/another-module/index.js"
      }
    }
Then run node like: `node --import-map=./import-map.json app.js`

The Debian approach of having global versions of libraries seems like it's solving a different problem than the ones I have. I want each application to track and version its own dependencies, so that upgrading a dependency for one doesn't break another, and so that I can go back to an old project and be reasonably confident it'll still work. That ultimately led me to nix.

Re: JSON River – Parse JSON incrementally as it streams in

#59
I really like just encoding each object as JSON and then concatinating them with a new line between.

Allows parsing and streaming without any special libraries and allow for an unlimited amount of data (with objects being reasonably sized).

Usually gives these files the .jsonlines suffix when stored on disk.

Allows for batch process without requiring huge amounts of memory.

Re: JSON River – Parse JSON incrementally as it streams in

#60
post #35

Hi HN! Didn't expect this to be on the front page today! I should really release all the optimizations that've been landing lately, the version on github is about twice as fast as what's released on npm. I wrote it when I was doing prototyping on doing streaming rendering of UIs defined by JSON generated by LLMs. Using constrained generation you can essentially hand the model a JSON serializable type, and it will alw…

Suggestion: make it clearer in the readme what happens with malformed input.

I can imagine it being useful to have a made where you never emit strings until they are final, also. I don't entirely understand why strings are emitted incrementally but numbers aren't.

Post reply on HN