Live data from Hacker News

JSON River – Parse JSON incrementally as it streams in

github.com

21–30 of 101 posts

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

#21

Maybe I'm wrong but it seems like you would only want to parse partial values for objects and arrays, but not strings or numbers. Objects and arrays can be unbounded so it makes sense to process what you can, when you can, whereas a string or number usually is not.

If you're generating long reports, code, etc. with an LLM, partial strings matter quite a lot for user experience.

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

#22

Maybe I'm wrong but it seems like you would only want to parse partial values for objects and arrays, but not strings or numbers. Objects and arrays can be unbounded so it makes sense to process what you can, when you can, whereas a string or number usually is not.

Numbers, booleans, and nulls are atomic with jsonriver, you get them all at once only when they're complete.

For my use case I wanted streaming parse of strings, I was rendering JSON produced by an LLM, for incrementally rendering a UI, and some of the strings were long enough (descriptions) that it was nice to see them render incrementally.

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

#23
post #16
post #13

Earlier quoted context omitted.

If you're building a UI that renders output from a streaming LLM you might get back something which looks like this: {"role": "assistant", "text": "Here's that Python code you aske Incomplete parsing with incomplete strings is still useful in order to render that to your end user while it's still streaming in.

incomplete strings could be fun in certain cases {"cleanup_cmd":"rm -rf /home/foo/.tmp" }

Yeah, another fun one is string enums. Could tread "DeleteIfEmpty" as "Delete".

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

#24
post #17

For those wondering about the use case, this is very useful when enabling streaming for structured output in LLM responses, such as JSON responses. For my local Raspberry Pi agent I needed something performant, I've been using streaming-json-js [1], but development appears to have been a bit dormant over the past year. I'll definitely take a look at your jsonriver and see how it compares! [1] https://github.com/karmi…

Particularly for REACT style agents that use a "final" tool call to end the run.

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

#26
You could also use JSON Merge Patch (RFC 7396) for a similar use case.

(The downside of JSON Merge Patch is it doesn't support concatenating string values, so you must send a value like `{"msg": "Hello World"}` as one message, you can't join `{"msg": "Hello"}` with `{"msg": " World")`.)

[1] https://github.com/pierreinglebert/json-merge-patch

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

#27
post #25

> If you gave this to jsonriver one byte at a time it would yield this sequence of values: Does it create a new value each time, or just mutate the existing one and keep yielding it?

It mutates the existing value and yields it again (unless the toplevel value is a string, because strings are immutable in JS).

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

#28

I don't get it (and I'd call this cumulative not incremental) Why not at least wait until the key is complete - what's the use in a partial key?

Cumulative is a good term too. I come from the browser world where it's typically called incremental parsing, e.g. when web browsers parse and render HTML as it streams in over the wire. I was doing the same thing with JSON from LLMs.

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

#29
post #6

I can't imagine a usecase. Ok, you receive incremental updates, which could be useful, but how to find out that json object is actually received in full already?

When you want to pull multi-gig JSON files and not wait for the full file before processing is where I first used this.

Funnily enough, this was one of the first users of jsonriver at google. A team needed to parse more JSON than most JS VMs will allow you to fit into a single string, so they had no choice but to use a streaming parser.

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

#30
post #26

You could also use JSON Merge Patch (RFC 7396) for a similar use case. (The downside of JSON Merge Patch is it doesn't support concatenating string values, so you must send a value like `{"msg": "Hello World"}` as one message, you can't join `{"msg": "Hello"}` with `{"msg": " World")`.) [1] https://github.com/pierreinglebert/json-merge-patch

[deleted]
Post reply on HN