So, thanks to @T.J.Crowder, I managed to locate a wrong method call I was making. Got a working code now:
const StreamObject = require('stream-json/streamers/StreamObject');
const fs = require('fs');
const _ = require('underscore');
const jsonStream = StreamObject.withParser();
var inputfile = "~Path/5cd792a633e32a6e5e20e56a.geojson";
var outputfile = "~Path/5cd792a633e32a6e5e20e56a.json";
var outstream = fs.createWriteStream(outputfile);
outstream.writable = true;
jsonStream.on('data', ({key, value}) => {
if (_.difference(['features'], Object.keys(value)).length === 0 ){
outstream.write(JSON.stringify(Object.values(value['features'])));
}
});
jsonStream.on('end', () => console.log('Done Export!'));
fs.createReadStream(inputfile).pipe(jsonStream.input);
Basically, all I am doing is reading a geojson file that is stored locally and exporting the array of data['data']['features'] to another external json file. This is just an sample here and geojson and exported array/json might get pretty big.
NOW, although I managed to achieve it by merging different stackoverflow posts, not sure if it's supposed to do the right job and the whole array is not being stored in RAM at once. Especially, the way if
statement is being used to write output. Please correct the code, if necessary.
Thanks!