Main module - uhop/stream-json GitHub Wiki
The main module returns a factory function that creates a parser stream decorated with emit().
const makeParser = require('stream-json');
const fs = require('fs');
const pipeline = fs.createReadStream('sample.json').pipe(makeParser());
let objectCounter = 0;
pipeline.on('startObject', () => ++objectCounter);
pipeline.on('end', () => console.log(`Found ${objectCounter} objects.`));The returned factory function takes one optional argument: options, and returns a Duplex parser stream decorated with emit().
const make = options => emit(parser.asStream(options));Re-exports the parser factory. Streams created with parser() or parser.asStream() are not decorated by emit(), which avoids the event overhead.
const {parser} = require('stream-json');
const fs = require('fs');
const pipeline = fs.createReadStream('sample.json').pipe(parser.asStream());
let objectCounter = 0;
pipeline.on('data', data => data.name === 'startObject' && ++objectCounter);
pipeline.on('end', () => console.log(`Found ${objectCounter} objects.`));