Class: StreamingJsonParser
Defined in: packages/core/src/utils/streaming-parser.ts:19
StreamingJsonParser
Utility for extracting text from streaming JSON responses. Handles partial JSON, escape sequences, and incremental updates.
Example
const parser = new StreamingJsonParser('response');
// As JSON streams in...
parser.append('{"response":"Hello ');
parser.getText(); // "Hello "
parser.append('world"}');
parser.getText(); // "Hello world"
Constructors
Constructor
new StreamingJsonParser(
field?,debug?):StreamingJsonParser
Defined in: packages/core/src/utils/streaming-parser.ts:31
Parameters
field?
string = 'response'
debug?
boolean = false
Returns
StreamingJsonParser
Methods
append()
append(
chunk):void
Defined in: packages/core/src/utils/streaming-parser.ts:40
Append a chunk of JSON to the buffer
Parameters
chunk
string
Returns
void
getNewText()
getNewText():
string
Defined in: packages/core/src/utils/streaming-parser.ts:75
Get only the new text since last call Returns empty string if no new content
Returns
string
getRaw()
getRaw():
string
Defined in: packages/core/src/utils/streaming-parser.ts:67
Get the raw extracted text (still escaped)
Returns
string
getText()
getText():
string
Defined in: packages/core/src/utils/streaming-parser.ts:60
Get the extracted text (unescaped, ready to display)
Returns
string
reset()
reset():
void
Defined in: packages/core/src/utils/streaming-parser.ts:89
Reset the parser state
Returns
void