Documentation
¶
Overview ¶
Package jsonx provides best-effort JSON recovery for model output. Streamed tool arguments are often malformed — unescaped control characters, bad escapes, or a stream cut off mid-token — so a strict decode would discard everything. These helpers repair and complete such input so callers can salvage whatever was received instead of failing the surrounding response.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Complete ¶
Complete closes the open containers and string of a truncated JSON document, returning a syntactically complete string. It tracks the longest prefix that, once its open containers are closed, parses as valid JSON, and discards any trailing partial token (an unterminated number, literal, key, or dangling separator). An unterminated string in a value position is closed in place so its received characters are kept. ok is false when no non-empty closeable prefix exists.
It salvages tool arguments whose JSON stream was cut short. Callers must still decode the result, which rejects any completion that does not parse.
func DecodeObject ¶
DecodeObject strictly decodes raw into a JSON object. ok is false when the input is not a valid, non-null JSON object.
func ParsePartialObject ¶
ParsePartialObject closes the open containers and strings of a truncated JSON document, then decodes the completed text as an object. ok is false when the input cannot be completed into a valid JSON object.
func Repair ¶
Repair fixes malformed JSON string literals by escaping raw control characters inside strings and doubling backslashes before invalid escape characters, while preserving valid escapes and \uXXXX sequences. Only ASCII characters carry special meaning here, so iterating over bytes leaves multi-byte UTF-8 sequences untouched.
Types ¶
This section is empty.