zemirco / json2csv-stream

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

Command line #17

Closed mfulton26 closed 6 years ago

mfulton26 commented 6 years ago

Similar to json2csv it would be great if the streaming support could be exposed via a command line tool. I have some very large JSON documents that I get periodically and json2csv works great but is rather slow but I suspect it would be faster if it were streamed from stdin to stdout (or to a file). Thanks.

knownasilya commented 6 years ago

Have a look out for a new release of json2csv which now includes streaming support (the cli streams by default). This library will be deprecated.

mfulton26 commented 6 years ago

Sweet.

mfulton26 commented 6 years ago

Should that solve the following problem I just ran into?

/usr/lib/node_modules/json2csv/lib/json2csv.js:330
      Array.prototype.push.apply(dataRows, dataRow);
                           ^

RangeError: Maximum call stack size exceeded
    at /usr/lib/node_modules/json2csv/lib/json2csv.js:330:28
    at Array.forEach (native)
    at createDataRows (/usr/lib/node_modules/json2csv/lib/json2csv.js:323:18)
    at createColumnContent (/usr/lib/node_modules/json2csv/lib/json2csv.js:209:3)
    at module.exports (/usr/lib/node_modules/json2csv/lib/json2csv.js:60:13)
    at /usr/lib/node_modules/json2csv/bin/json2csv.js:136:15
    at getInput (/usr/lib/node_modules/json2csv/bin/json2csv.js:60:12)
    at /usr/lib/node_modules/json2csv/bin/json2csv.js:104:3
    at getFields (/usr/lib/node_modules/json2csv/bin/json2csv.js:49:5)
    at Object.<anonymous> (/usr/lib/node_modules/json2csv/bin/json2csv.js:99:1)
knownasilya commented 6 years ago

Yes, if you use the streams API. You can test it now using the master branch.

mfulton26 commented 6 years ago

I tried it out but I'm sure I'm missing something. Does this support unwinding too like json2csv?

knownasilya commented 6 years ago

Master branch here: https://github.com/zemirco/json2csv, the streaming API supports all of the same options as the non streaming API. The docs are here: https://github.com/zemirco/json2csv#json2csv-transform-streaming-api

mfulton26 commented 6 years ago

Oh, I used the master branch of json2csv-stream, I'll try json2csv, my mistake. Thanks.