Dev Helpers

Node.js / Streams

Parse a streamed JSON document

Dev Helpers · May 5, 2026

A streamed JSON document must be framed before parsing. A single JSON document and newline-delimited JSON have different boundaries.

Worked example

import {
  Readable,
  Writable,
  Transform,
  PassThrough,
  isReadable,
  isWritable,
} from "node:stream";
import { text, json, arrayBuffer } from "node:stream/consumers";
import { pipeline, finished } from "node:stream/promises";
console.log(await json(Readable.from(['{"n":', "7}"])));

Result

{ n: 7 }

Implementation notes

Parsing records one at a time requires a defined delimiter or frame. A newline inside formatted JSON is not always a record boundary.

Try it yourself

Split the sample just before a closing brace.

Open the Node.js example →

Editorial date May 5, 2026 · Published December 6, 2026

Related articles

Safely parse malformed input

Parsing user-provided JSON needs a failure path. Successful parsing alone does not establish that the result has the expected shape.

Checksum bytes with CRC32

CRC32 is useful for detecting accidental changes to a byte sequence. Record the input encoding so different producers compute the same checksum.

Attach details to a mark

Performance marks can carry details about the operation they describe. Small stable identifiers are easier to aggregate than large payloads.