zemirco / json2csv-stream

Transform stream from json to csv
52 stars 17 forks source link

Convert json object stream #13

Closed chriszrc closed 5 years ago

chriszrc commented 6 years ago

I'm streaming json data from postgres to csv files. Currently, it seems I have to do this:

stream.pipe(JSONStream.stringify()).pipe(json2CsvParser).pipe(writer);

That is, even though I already have valid json objects, I have to first stringify it, then convert to csv. Is this really the right way to achieve this streaming transformation? Can json2csv-stream accept json rather than a string?

sarkistlt commented 6 years ago

trying to do almost the same with mongoose, stream.pipe(JSONStream.stringify()).pipe(json2CsvParser).pipe(writer); but in my case stream will return JS object so first I need to convert it to JSON, but code above gives me error: SyntaxError: Unexpected end of JSON input

knownasilya commented 6 years ago

Give the 4.0-alpha a try here https://github.com/zemirco/json2csv it now includes stream support.

This library will be deprecated.

sarkistlt commented 6 years ago

works, thanks

knownasilya commented 5 years ago

https://github.com/zemirco/json2csv now has a streams API, please use that module as this one is deprecated/unmaintained.