dominictarr / JSONStream

rawStream.pipe(JSONStream.parse()).pipe(streamOfObjects)
Other
1.92k stars 165 forks source link

Returning a single object #72

Closed duncanmak closed 9 years ago

duncanmak commented 9 years ago

Hello,

If my JSON body is just a single object, and that's what I want to get out of the data event, what's the right expression? I tried "$", but that didn't work for me.

Also, I read in #47 that there's a root event, but I didn't get anything out of that, is the event available?

dominictarr commented 9 years ago

If you have just a single object, don't stream it, just buffer and then use JSON.parse. JSON.parse is highly optimized C built into v8 so it will be very fast. JSONStream is javascript, so it's slow.

Why use JSONStream at all then? If the input is too large (hundreds of megs) it will crash JSON.parse! or sometimes you need results on the fly, use JSONStream. Otherwise, use JSON.parse