JSONStream (GitHub: dominictarr/JSONStream, License: Apache) is a module by Dominic Tarr for streaming JSON.parse
and JSON.stringify
.
npm install jsonstream
Usage
var request = require('request'),
JSONStream = require('JSONStream'),
es = require('event-stream')
;
var parser = JSONStream.parse(['rows', true]),
req = request({url: 'http://isaacs.couchone.com/registry/_all_docs'}),
logger = es.mapSync(function (data) {
console.error(data);
return data;
})
request({url: 'http://isaacs.couchone.com/registry/_all_docs'})
.pipe(JSONStream.parse('rows.*'))
.pipe(es.mapSync(function (data) {
console.error(data);
return data;
}));
gulp.js very nicely. The really cool thing for me is that you can react to specific nodes in the data structure vs having to seek them out and loop over them manually.
I like the idea behind streaming JSON alot because you don’t have to wait for the whole document to come down the pipe, especially if it’s very large. It can also integrate withAre you dealing with large JSON structures on your project?