JSON River – Parse JSON incrementally as it streams in
81–90 of 101 posts
Re: JSON River – Parse JSON incrementally as it streams in
#82Re: JSON River – Parse JSON incrementally as it streams in
#83Earlier 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
#84Earlier quoted context omitted.
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.
Seems useful to me in the context of something like a progressively rendered UI. A large block of text appearing a few characters at a time would be fine, but a number that represents something like a display metric (say, a position, or font-size) going from 0 to 0.5 or from 1 to 1000, would result in goofy gyrations on-screen that don't make any sense. Or imagine if it was just fields in the app's data. Name: John S…
Re: JSON River – Parse JSON incrementally as it streams in
#85Earlier quoted context omitted.
Seems useful to me in the context of something like a progressively rendered UI. A large block of text appearing a few characters at a time would be fine, but a number that represents something like a display metric (say, a position, or font-size) going from 0 to 0.5 or from 1 to 1000, would result in goofy gyrations on-screen that don't make any sense. Or imagine if it was just fields in the app's data. Name: John S…
If you're updating the UI every time you receive a single character from this library, you've got bigger problems than font size.
(but for other uses - nope)
Re: JSON River – Parse JSON incrementally as it streams in
#86Earlier quoted context omitted.
Don't you need to wait for some kind of delimiter (like ",", "]", "}", newline, EOF) before parsing something else than a string?
Only for numbers! Strings, objects, arrays, true, false, and null all have an unambiguous ending.
{"name": "Ale"}Re: JSON River – Parse JSON incrementally as it streams in
#87Interesting approach. I would expect an object JSON stream to be more like a SAX parser though. It's familiar, fast and simple. Any thougts on not chosing the SAX approach?
Re: JSON River – Parse JSON incrementally as it streams in
#88Earlier quoted context omitted.
incomplete strings could be fun in certain cases {"cleanup_cmd":"rm -rf /home/foo/.tmp" }
Incremental JSON parsing is key for LLM apps, but safe progressive UIs also need to track incompleteness and per-chunk diffs. LangDiff [1] would help with that. [1]: https://github.com/globalaiplatform/langdiff/tree/main/ts
Re: JSON River – Parse JSON incrementally as it streams in
#89If anyone needs to do this in Python I've had success with both ijson and jiter - notes here: https://til.simonwillison.net/json/ijson-stream and https://simonwillison.net/2024/Sep/22/jiter/