Skip to main content

Module partial_json

Module partial_json 

Source
Expand description

Repair and parse truncated JSON.

Streaming models emit JSON text incrementally. repair closes open strings, arrays and objects, completes partial literals (trutrue) and drops trailing separators so that any prefix of a valid document becomes parseable. parse_partial tries a direct parse first and falls back to repair.

Derived from the fixJson state machine of the Vercel AI SDK (Apache-2.0, Copyright 2023 Vercel, Inc.), translated from TypeScript to Rust and modified; see NOTICE.

Structs§

PartialParse
Outcome of parse_partial.

Enums§

PartialParseState
How a partial parse succeeded or failed.

Functions§

parse_optional
Parses optional JSON text, distinguishing absent input from invalid JSON.
parse_partial
Parses text, repairing it first if a direct parse fails.
repair
Repairs truncated JSON so that it parses.