push-stream-std

@push-stream-std/push-json-parse (0.0.5)

Published 2026-07-19 22:47:11 +00:00 by Dvorak

Installation

@push-stream-std:registry=https://hub.kl1.tenere.ai/api/packages/push-stream-std/npm/
npm install @push-stream-std/push-json-parse@0.0.5
"@push-stream-std/push-json-parse": "0.0.5"

About this package

push-json-parse

Streaming JSON parsing.

Published as @push-stream-std/push-json-parse.

Synopsis

import { parse, parseArray, parseLines } from '@push-stream-std/push-json-parse';
import { values } from '@push-stream-std/push-values';
import { collect } from '@push-stream-std/push-collect';

// Parse a JSON array arriving in chunks
const chunks = ['[1,2,', '3,"hello"]'];
values(chunks)
  .pipe(parse({ mode: 'array' }))
  .pipe(collect((err, results) => {
    console.log(results); // [[1, 2, 3, 'hello']]
  }));

// Parse individual JSON lines (NDJSON)
values(['{"a":1}\n{"b":2}\n'])
  .pipe(parse({ mode: 'lines' }))
  .pipe(collect((err, results) => {
    console.log(results); // [{a: 1}, {b: 2}]
  }));

Install

npm config set @push-stream-std:registry https://hub.kl1.tenere.ai/api/packages/push-stream-std/npm/
npm config set -- //hub.kl1.tenere.ai/api/packages/push-stream-std/npm/:_authToken "$PACKAGE_TOKEN"
npm install @push-stream-std/push-json-parse

Description

Parses JSON data streaming through a push-stream, handling partial chunks that may arrive across multiple writes. Supports three modes: 'array' for parsing comma-separated JSON array elements as they arrive (tracking depth and string escaping), 'lines' for newline-delimited JSON, and 'complete' for a single top-level JSON value. Remaining unparseable data at stream end causes the sink's end to be called with the parse error.

API

parse(options)

Creates a through stream that parses incoming string data as JSON.

Parameters:

  • options.mode (string, default 'array') — Parsing mode: 'array', 'lines', or 'complete'.

Returns: A push-stream through.

parseArray(options)

Convenience wrapper that calls parse({ ...options, mode: 'array' }).

Returns: A push-stream through.

parseLines(options)

Convenience wrapper that calls parse({ ...options, mode: 'lines' }).

Returns: A push-stream through.

Tests

npm test

Tests cover parsing of complete arrays, partial chunk assembly, newline-delimited JSON lines, single complete values, empty inputs, and malformed JSON error handling.

Requirements

Node.js 18 or later. ESM only.

License

MIT

Keywords

push-stream json parse ndjson
Details
npm
2026-07-19 22:47:11 +00:00
0
MIT
3.8 KiB
Assets (1)
Versions (6) View all
0.0.9 2026-07-21
0.0.8 2026-07-20
0.0.7 2026-07-20
0.0.6 2026-07-19
0.0.5 2026-07-19