Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

json-streaming-reader

FireBlinkLTD14MIT1.0.2TypeScript support: included

Line delimited and concatenated JSON streaming protocol reader.

fireblink, json, stream, concatenated, line, delimited, streaming, parser, reader, protocol

readme

JSON Streaming Protocol Reader

Greenkeeper badge CircleCI codecov

Simple JSON streaming protocol parser that allows to handle each record individually.

Supported Stream Types

Line-delimited JSON

Fully supported.

Concatenated JSON

Supported for non-primitive types. Only objects, arrays and their combination as records are supported.

So, following string value will be parsed correctly:

{a: 1}[213]

while next will not:

{a: 1}null"string"123

Record separator-delimited JSON

Not supported.

Length-prefixed JSON

Not supported.

Usage

If you use NPM:

npm i --save json-streaming-reader

If you use YARN:

yarn add json-streaming-reader

Then just import JsonStream like this:

// if you use JavaScript:
const JsonStreamReader = require('json-streaming-reader').JsonStreamReader;

// or if you use TypeScript:
import {JsonStreamReader} from 'json-streaming-reader'

And pipe the reading stream to it like this:

const jsonStream = new JsonStreamReader();
readStream.pipe(jsonStream);

jsonStream.on('data', (data) => {
    // do something with the record
    // NOTE: `data` is an object with single field `record` that hosts actual value.
    const {record} = data.record;

    console.log(record);
});