Skip to content

Allow partial/incomplete JSON to be parsed #1288

@martinrlilja

Description

@martinrlilja

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:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions