New-line separated JSON streaming

npm install newline-json
1 downloads in the last day
3 downloads in the last week
38 downloads in the last month


Just like JSONStream, but instead of streaming valid JSON arrays, it streams new-line separated JSON objects.


If you have a readable stream like

var n = 100;
var nlj = new Readable();
nlj._read = function _read () {
  if (n--)
    nlj.push('{"this":"is","js":"on"}\n'); // new-line separated JSON!
return nlj;

you can pipe it to the parser

var Parser = require('newline-json').Parser;
var parser = new Parser();

what comes out of the parser will be the the objects you piped to it, parsed. You can pipe those again to the stringifier:

var Stringifier = require('newline-json').Stringifier;
var stringifier = new Stringifier();

And if you have nothing better to do today, be sure to try


Why ?

Couldn't find one on npm that used the Transform, and IMO if you don't need to parse complex object paths, then you'd be better off using a new-line separated JSON. Also, it's probably much easier to write parsers like this in other languages and environments, which is good if your stack is not 100% node.js.

npm loves you