Closed kitlung closed 6 years ago
That's done in Example 6 of the readme.
Just use the quote option quote: ''
.
@juanjoDiaz
This will remove all quote. The result in Example 2 is what I want.
But I get an error
TypeError: Json2csvParser is not a constructor
when following the example.
Are you really using version 4.X? That last error looks like you are using 3.X but calling as if it was 4.X. and var csv = json2csv({ data: csvArr, fields: fields})
is definitely 3.X API.
Can you post a running code sample, please? Then I can help you with that error :)
Regarding removing the quotes from the headers but not from anything else. It was requested on #195 but is not implemented.
You can do it with some post processing though:
var csv = '"acb"\n"fhk"'
const rows = csv.split('\n');
const header = rows.shift().replace(/"/g, '');
rows.unshift(header);
csv = rows.join('\n');
It works, thank you. I have checked the package.json and package-lock.json, the version is 4.2.0
Using version 4.2,
var fields = ['CardNumber', 'BatchID', 'ValueNumber', 'Value', 'ExpDate', 'ExpDateDisplay']
csvObj = {
'CardNumber' : "...",
'BatchID' : "...",
'ValueNumber' : "...",,
'Value' : "...",,
'ExpDate' : "...",,
'ExpDateDisplay' : "..."
}
csvArr.push(csvObj)
var csv = json2csv({ data: csvArr, fields: fields})
console.log(csv)
Result: "CardNumber","BatchID","ValueNumber","Value","ExpDate","ExpDateDisplay" "...", "...", "...", "...", "...", "..." "...", "...", "...", "...", "...", "..."
However, I want to remove those double quote in fields. Are there any possible solutions?