Created
December 17, 2015 23:32
-
-
Save cspotcode/6dec53180baab9ac2d14 to your computer and use it in GitHub Desktop.
Parsing streaming JSON with Oboe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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