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.
JSON River – Parse JSON incrementally as it streams in
21–30 of 101 posts
Re: JSON River – Parse JSON incrementally as it streams in
#22Maybe 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.
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
#23Earlier 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" }
Re: JSON River – Parse JSON incrementally as it streams in
#24For 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…
Re: JSON River – Parse JSON incrementally as it streams in
#25Does it create a new value each time, or just mutate the existing one and keep yielding it?
Re: JSON River – Parse JSON incrementally as it streams in
#26(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")`.)
Re: JSON River – Parse JSON incrementally as it streams in
#27> 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?
Re: JSON River – Parse JSON incrementally as it streams in
#28I 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?
Re: JSON River – Parse JSON incrementally as it streams in
#29I 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.
Re: JSON River – Parse JSON incrementally as it streams in
#30You 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