zemirco / json2csv

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

if fieldNames has '"', ',', the result csv format error #159

Closed MapleMaster closed 6 years ago

MapleMaster commented 7 years ago

when I use " in fieldNames, it didn't convert " to "" as the value column did this convert.

like data:[ { name: 'maple"maple', age: 23 }] get csv data:"maple""maple",23, but fieldNames: [ 'name"name', 'age' ] get csv title: "name\"name","age", not "name""name","age", which will occur excel format error.

PS: lib/json2csv.js +157: str += JSON.stringify(element).replace(/\"/g, params.quotes); maybe str += JSON.stringify(element).replace(/\\"/g, params.doubleQuotes); ? cause " JSON.stringfiy get \\"

knownasilya commented 7 years ago

PRs welcome 👍