Skip to main content

@std/json@0.215.0

latest
Works with
It is unknown whether this package works with Browsers, Deno, Node.js, Cloudflare Workers, Bun
It is unknown whether this package works with Browsers
It is unknown whether this package works with Deno
It is unknown whether this package works with Node.js
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Bun
JSR Score70%
Published2 years ago (0.215.0)
class JsonParseStream

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.

Examples

parse JSON lines or NDJSON

import { TextLineStream } from "@std/streams/text_line_stream";
import { JsonParseStream } from "@std/json/json_parse_stream";

const url = "@std/json/testdata/test.jsonl";
const { body } = await fetch(url);

const readable = body!
  .pipeThrough(new TextDecoderStream())  // convert Uint8Array to string
  .pipeThrough(new TextLineStream()) // transform into a stream where each chunk is divided by a newline
  .pipeThrough(new JsonParseStream()); // parse each chunk as JSON

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

parse JSON Text Sequences

import { TextDelimiterStream } from "@std/streams/text_delimiter_stream";
import { JsonParseStream } from "@std/json/json_parse_stream";

const url =
  "@std/json/testdata/test.json-seq";
const { body } = await fetch(url);

const delimiter = "\x1E";
const readable = body!
  .pipeThrough(new TextDecoderStream())
  .pipeThrough(new TextDelimiterStream(delimiter)) // transform into a stream where each chunk is divided by a delimiter
  .pipeThrough(new JsonParseStream());

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

Constructors

new JsonParseStream(unnamed 0?: ParseStreamOptions)

Constructs new instance.

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@std/json

Import symbol

import { JsonParseStream } from "@std/json/json_parse_stream";
or

Import directly with a jsr specifier

import { JsonParseStream } from "jsr:@std/json/json_parse_stream";