zemirco / json2csv

Convert json to csv with column titles
http://zemirco.github.io/json2csv
MIT License
2.72k stars 363 forks source link

Not sure if possible to use this with async await #295

Closed kpennell closed 6 years ago

kpennell commented 6 years ago

With all due respect to this awesome library...I recommend not trying to use it with async await. No idea why I couldn't get it working...Would love those 2 hours back! 😠

Oh well....try this instead: https://stackoverflow.com/questions/8847766/how-to-convert-json-to-csv-format-and-store-in-a-variable

knownasilya commented 6 years ago

This library is sync thus doesn't require async await. What were you attempting?

kpennell commented 6 years ago

Was trying to get data from an async operation...then when it finished...convert it to csv and download.

Anyway, feel free to close. Just trying to spare someone a lot of effort.

On Wed, May 9, 2018 at 3:58 PM, Ilya Radchenko notifications@github.com wrote:

This library is sync thus doesn't require async await. What were you attempting?

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/zemirco/json2csv/issues/295#issuecomment-387900025, or mute the thread https://github.com/notifications/unsubscribe-auth/ABAuIdPdecQyVpQvkPBWky9Jb6D5oK5eks5tw3SwgaJpZM4T5HTp .

knownasilya commented 6 years ago

Just pass the Json after your Await to json2csv directly :)

kpennell commented 6 years ago

thx!

On Wed, May 9, 2018 at 4:41 PM, Ilya Radchenko notifications@github.com wrote:

Just pass the Json after your Await to json2csv directly :)

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/zemirco/json2csv/issues/295#issuecomment-387907266, or mute the thread https://github.com/notifications/unsubscribe-auth/ABAuIYwkyhhiiE1QtPjUlRfOUNLkI3OJks5tw367gaJpZM4T5HTp .

juanjoDiaz commented 6 years ago

The stack overflow link that you put is a largely oversimplified CSV conversion. We do a bit more escaping, quoting, headers, etc.

As it has been mention, json2csv is sync. I assume that all you want to do is:

const jsonData = await getMyData();
const csvData = json2csv.parse(jsonData);

If you still want to, feel free to add a code example of your issue and I can tell you what's wrong :)