Skip to main content
Go to Latest
class JsonStringifyStream
extends TransformStream<unknown, string>
import { JsonStringifyStream } from "https://deno.land/std@0.158.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.158.0/streams/mod.ts";
import { JSONStringifyStream } from "https://deno.land/std@0.158.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)