Consider the following:
import { parseNestedJsonStreamWithPaths, streamToIterable } from "json-stream-es";
const json = `{
"a": 1,
"b": 2,
"c": [
"this",
"that"
],
"d": {
"inside": [],
"hey": null
}
}`;
const stream = new ReadableStream({
start(controller) {
controller.enqueue(json);
controller.close();
}
});
const jsonStream = stream.pipeThrough(parseNestedJsonStreamWithPaths([]));
for await (const substream of streamToIterable(jsonStream)){
for await (const { path, value } of streamToIterable(substream)) {
console.log(substream.path, path, value);
}
}
This code will work on Node.JS, but it will fail on Deno:
Internal Error: AssertionError: Assertion failed.
at assert (ext:deno_web/00_infra.js:396:11)
at readableStreamAddReadRequest (ext:deno_web/06_streams.js:1711:3)
at ReadableStreamDefaultController.[[[PullSteps]]] (ext:deno_web/06_streams.js:6212:7)
at readableStreamDefaultReaderRead (ext:deno_web/06_streams.js:2623:36)
at ext:deno_web/06_streams.js:2854:9
at new Promise (<anonymous>)
at ext:deno_web/06_streams.js:2853:14
error: Top-level await promise never resolved
for await (const { path, value } of streamToIterable(substream)) {
^
at <anonymous> (file:///:28:19)
Trying to manually recreate the pipe errors out when I add JsonPathStreamSplitter:
const jsonStream = stream
.pipeThrough(new JsonParser())
.pipeThrough(new JsonPathDetector())
.pipeThrough(new JsonPathSelector([]))
.pipeThrough(new JsonPathStreamSplitter()) <-- assertion fails when this is present
for await (const substream of streamToIterable(jsonStream)){
console.log(substream)
}
Consider the following:
This code will work on Node.JS, but it will fail on Deno:
Trying to manually recreate the pipe errors out when I add JsonPathStreamSplitter: