-
Notifications
You must be signed in to change notification settings - Fork 607
Description
When using LLMs to generate JSON it is often nice to be able parse incomplete or partial JSON while data is being generated.
For example, being able to parse these could make user interfaces look more responsive:
{"text": "some long text string...
or
["a", "very", "long", "list
Pydantic has added this feature for the same reason. https://docs.pydantic.dev/latest/concepts/json/#partial-json-parsing It is implemented in their Rust based JSON parser jiter
There are a few other projects which try to do similar things:
- json-stream-rust
- llm_json broader in scope
- serde_json_lenient doesn't seem to support partial json
I think adding this feature to serde json would be beneficial as it is probably the most common json library for rust, so it is the first place most people would look. Also in my testing the changes required are not massive.
A drawback to adding it to serde json is that it requires us to re-parse the whole json structure every time we receive an update, so for performance reasons, some developers might opt for a more suitable crate that allows streaming.