2.0.0 • Published 4 years ago

json-split-stream v2.0.0

Weekly downloads
266
License
MIT
Repository
github
Last release
4 years ago

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