{ } qjs-modules

jsonStreams

Source: lib/jsonStreams.js (pure JS, portable)

Deno's @std/json streams as WHATWG TransformStreams. Results match jsr:@std/json on every case in tests/unittests/test-jsonstreams.js, which also runs on node, bun and deno.

Needs the TransformStream global. Under qjsm the global streams from globals have no pipeTo/pipeThrough; use the classes of lib/stream.js.

Exports

ClassWritableReadableBehavior
JsonParseStreamstringanyone JSON value per chunk (a line); empty chunks skipped; SyntaxError on a bad chunk
ConcatenatedJsonParseStreamstringanyback-to-back values ({}{}, []{}, 1 2), any chunking; SyntaxError on bad or truncated input
JsonStringifyStreamanystringprefix + JSON.stringify(value) + suffix

Every constructor takes { writableStrategy, readableStrategy }; JsonStringifyStream also { prefix = '', suffix = '\n' }.

values.pipeThrough(new JsonStringifyStream());                       // '{"a":1}\n'
values.pipeThrough(new JsonStringifyStream({ prefix: '\x1e' }));     // RFC 7464
chunks.pipeThrough(new ConcatenatedJsonParseStream());               // {a: 1}, [2], ...

A number or literal in ConcatenatedJsonParseStream ends at whitespace, {, [, " or the end of the stream. JsonParseStream expects complete values per chunk: put a TextLineStream in front for newline-delimited input, or use JSONL.parseChunk from json with a carried tail.

Export list

Generated by utilities/doc-api.js from the jsonStreams dump of utilities/api-surface.sh: 6 members. Edit the text above this block, not the block.

ConcatenatedJsonParseStream

class, constructible

JsonParseStream

class, constructible

JsonStringifyStream

class, constructible