import { JSONStringifyStream } from "https://deno.land/std@0.149.0/encoding/json/stream.ts";
Convert each chunk to JSON string.
This can be used to stringify JSON lines, NDJSON, JSON Text Sequences, and Concatenated JSON. You can optionally specify a prefix and suffix for each chunk. The default prefix is "" and the default suffix is "\n".
import { readableStreamFromIterable } from "https://deno.land/std@0.149.0/streams/mod.ts";
import { JSONStringifyStream } from "https://deno.land/std@0.149.0/encoding/json/stream.ts";
const file = await Deno.open("./tmp.jsonl", { create: true, write: true });
readableStreamFromIterable([{ foo: "bar" }, { baz: 100 }])
.pipeThrough(new JSONStringifyStream())
.pipeThrough(new TextEncoderStream())
.pipeTo(file.writable)
.then(() => console.log("write success"));
Constructors
new
JSONStringifyStream(unnamed 0?: StringifyStreamOptions)