JsonAccumulator class
Accumulates a JSON document that arrives in fragments and parses it tolerantly while still incomplete.
Tool-call arguments stream from the model as a sequence of partial JSON
strings. A naive jsonDecode of the buffer throws until the very last
fragment lands, which makes live rendering impossible. JsonAccumulator
instead repairs the partial buffer — closing open strings and containers and
dropping any trailing incomplete token — so callers can show a best-effort
view at every step, then validate strictly once the document is complete.
The repair is conservative: it never throws and never invents data. When a trailing value cannot be completed safely it is dropped rather than guessed, so parsePartial only ever returns a prefix of the eventual document.
Constructors
Properties
Methods
-
add(
String fragment) → void - Appends a fragment to the buffer.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
parsePartial(
) → Object? - Returns a best-effort decode of the (possibly partial) buffer.
-
reset(
) → void - Clears the buffer and cached partial result.
-
toString(
) → String -
A string representation of this object.
inherited
-
tryParseComplete(
) → Object? -
Strictly parses the buffer, returning
nullif it is not yet valid JSON.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited