json-split-stream

A fast way to split concatenated JSON data into individual chunks

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
json-split-stream
802.0.04 years ago6 years agoMinified + gzip package size for json-split-stream in KB

Readme

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