Skip to main content
Go to Latest
class JsonParseStream
extends TransformStream<string, JsonValue>
import { JsonParseStream } from "https://deno.land/std@0.158.0/encoding/json/stream.ts";

Parse each chunk as JSON.

This can be used to parse JSON lines, NDJSON and JSON Text Sequences. Chunks consisting of spaces, tab characters, or newline characters will be ignored.

import { TextLineStream } from "https://deno.land/std@0.158.0/streams/mod.ts";
import { JsonParseStream } from "https://deno.land/std@0.158.0/encoding/json/stream.ts";

const url = "https://deno.land/std@0.158.0/encoding/testdata/json/test.jsonl";
const { body } = await fetch(url);

const readable = body!
  .pipeThrough(new TextDecoderStream())
  .pipeThrough(new TextLineStream()) // or `new TextDelimiterStream(delimiter)`
  .pipeThrough(new JsonParseStream());

for await (const data of readable) {
  console.log(data);
}

Constructors

new
JsonParseStream(unnamed 0?: ParseStreamOptions)