json-split-stream

2.0.0 • Public • Published

json-split-stream

NPM Version NPM Downloads Build Status Coverage Status Dependency Status

A fast way to split concatenated JSON data into individual chunks.

Install: npm install json-split-stream

const JSONSplitStream = require('json-split-stream');
 
const chunker = new JSONSplitStream();  // is a Duplex stream
 
chunker.write('[1,2,3]{"a":12}');
chunker.read(); // => '[1,2,3]'
chunker.read(); // => '{"a":12}'
chunker.read(); // => null

Also supports not storing the incoming data and just emitting events for JSON boundaries (counted in JS string length, not bytes):

const chunker = new JSONSplitStream({ storeData: false });
chunker.on('finishedJSON', ({ jsonEnd }) => {
  console.log('ended at', jsonEnd);
});
 
chunker.write('[1,2,3]{"a":');
chunker.write('12}');
 
// Prints:
ended at 7
ended at 15

License

MIT

/json-split-stream/

    Package Sidebar

    Install

    npm i json-split-stream

    Weekly Downloads

    257

    Version

    2.0.0

    License

    MIT

    Unpacked Size

    12.9 kB

    Total Files

    7

    Last publish

    Collaborators

    • addaleax