zemirco / json2csv

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

fix: issue with string array #507

Closed enteve closed 3 years ago

enteve commented 3 years ago

Currently, if you got an string array, the csv output is like this:

"[""apple"",""orange""]"

which will raise error when trying to import to databases (in my case: clickhouse). The output should be

"['apple','orange']"

Reminder:

I only tested importing csv to Clickhouse. I didn't test other databases.

coveralls commented 3 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling 3863d71519cfa5b7967313a10dde215c01ddbf0a on enteve:master into 5c62da1d2559d366bbe135c13db2a2c6bd06a391 on zemirco:master.

juanjoDiaz commented 3 years ago

Hi @enteve ,

Double quote (") is the CSV default quote and double double-quote ("") is the default escaped quote. So "[""apple"",""orange""]" is the correct output.

This seems like an issue with Clickhouse and not something related to arrays. You'd get the same problem is you'd have strings container a double quote ("This is a quote: \"") or objects ({ a: 1, b: 2 }).

If you want double quote (") as the CSV quote and single quote (') as the escaped quote, simply set the escapedQuote option (escapedQuote: '\'').

juanjoDiaz commented 3 years ago

Closing since there is no response and my previous comment explains the right approach. Feel free to reopen if you think that's needed.