jimhigson / oboe.js

A streaming approach to JSON. Oboe.js speeds up web applications by providing parsed objects before the response completes.
http://jimhigson.github.io/oboe.js-website/index.html
Other
4.79k stars 208 forks source link

JSON-in-JSON causes the oboe parser to stumble #194

Closed reactormonk closed 5 years ago

reactormonk commented 5 years ago

Sample code:

const Readable = require('stream').Readable;
const s = new Readable();
s._read = () => {}; // redundant? see update below

const oboe = require('oboe');
const r = oboe(s);
r.on("done", console.log);

s.push('{"hello": "there"}'); // this one logs

const json = '{"log":"{\"level\":\"debug\",\"transformationError\":\"Something went wrong\"}","stream":"stdout","time":"2019-09-19T07:22:33.363566344Z"}';
s.push(json); // this one doens't
Aigeec commented 5 years ago

The json you are sending is two separate objects. Oboejs parses a single object. So as far as it was concerned it was 'done' after first object.

Try putting it in an array, i.e. send a [ then one of your objects followed by a , repeat until you are done and finish with ].

You would want to event on each node.

A

On Fri 20 Sep 2019, 14:29 Simon Hafner, notifications@github.com wrote:

Sample code:

const Readable = require('stream').Readable; const s = new Readable(); s._read = () => {}; // redundant? see update below

const oboe = require('oboe'); const r = oboe(s); r.on("done", console.log);

s.push('{"hello": "there"}'); // this one logs

const json = '{"log":"{\"level\":\"debug\",\"transformationError\":\"Something went wrong\"}","stream":"stdout","time":"2019-09-19T07:22:33.363566344Z"}'; s.push(json); // this one doens't

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jimhigson/oboe.js/issues/194?email_source=notifications&email_token=ABG3J3WXD5PI3SLRYX6BEIDQKTF5JA5CNFSM4IYXDIOKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HMVYHNA, or mute the thread https://github.com/notifications/unsubscribe-auth/ABG3J3X5LMIVS2WLOLBZAW3QKTF5JANCNFSM4IYXDIOA .

reactormonk commented 5 years ago

Right, forgot the level of escape I have to put it through.