Class: StreamingJsonParser
Defined in: packages/core/src/utils/streaming-parser.ts:17
Extracts one string field's text from JSON as it streams in, including partial values and escape sequences split across chunks.
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:29
Parameters
field?
string = 'response'
debug?
boolean = false
Returns
StreamingJsonParser
Methods
append()
append(
chunk):void
Defined in: packages/core/src/utils/streaming-parser.ts:35
Parameters
chunk
string
Returns
void
getNewText()
getNewText():
string
Defined in: packages/core/src/utils/streaming-parser.ts:63
Unescaped text added since the last call; '' when there is none.
Returns
string
getRaw()
getRaw():
string
Defined in: packages/core/src/utils/streaming-parser.ts:58
The field's text so far, still JSON-escaped.
Returns
string
getText()
getText():
string
Defined in: packages/core/src/utils/streaming-parser.ts:53
The field's text so far, unescaped.
Returns
string
reset()
reset():
void
Defined in: packages/core/src/utils/streaming-parser.ts:74
Returns
void