kaue / jsonexport

{} → :page_facing_up: it's easy to convert JSON to CSV
http://kaue.github.io/jsonexport/
Apache License 2.0
247 stars 41 forks source link

Handling of newline in string literal potential issue #6

Closed TomShriner closed 8 years ago

TomShriner commented 8 years ago

I saw an issue where one of my json entries contained a newline - example:

"q10":"blahblahblahe\n",

which seems to not get handled properly. Could I be missing an option to handle this or is there an issue with the character embedded in the string literal (or perhaps my json is not properly escaped - I retrieve via an external API which may be violating the json spec - but it looks right).

It should be valid in JSON to have a string containing a newline.

kaue commented 8 years ago

@TomShriner You could use the handleString option if you want to remove linebreaks from all strings, but i think another option would be to add the textDelimiter in the CSV when a linebreak is detected (needs to be tested) https://github.com/Cnova/jsonexport/blob/master/lib/index.js#L122

var options = {
    handleString: (string, name) => string.replace(/\n/g, '')
};