Skip to content

Instantly share code, notes, and snippets.

@cspotcode
Created December 17, 2015 23:32
Show Gist options
  • Save cspotcode/6dec53180baab9ac2d14 to your computer and use it in GitHub Desktop.
Save cspotcode/6dec53180baab9ac2d14 to your computer and use it in GitHub Desktop.
Parsing streaming JSON with Oboe
var oboe = require('oboe');
var stream = require('stream');
var Readable = stream.Readable;
var Writable = stream.Writable;
var readable = new Readable();
readable._read = function() {};
readable.push('{"some": "json"}{"more": [1, 2, 3], "json": true}{"final json object": 12345}{"stream continues...');
readable.push(null);
// Here's the oboe magic
var jsonReader = oboe(readable);
// Every time oboe finishes parsing a JSON object, fire this callback
jsonReader.on('done', function(json) {
// Got a JSON object
console.dir(json);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment