Skip to main content
Deno 2 is finally here 🎉️
Learn more
Go to Latest
The Standard Library has been moved to JSR. See the blog post for details.
class JsonStringifyStream
extends TransformStream<unknown, string>
import { JsonStringifyStream } from "https://deno.land/std@0.156.0/encoding/json/_stringify.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.156.0/streams/mod.ts";
import { JSONStringifyStream } from "https://deno.land/std@0.156.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)