i read the json2csv documentation and applied it in my program
const {parse} = require('json2csv')
header = [customerNo,Name,BranchCode,representive,overall]
list = [{cNo:1,name:Jack,bCode:3,rps:Bill,overall},{cNo:2,name:Justin,bCode:2,rps:Wade,overall:180}]
const fields = header;
const opts = { fields };
try {
var csv = parse(list,opts);
csv=csv.replace(/,/g,";")
console.log(csv);
} catch (err) {
console.log(err)
}
result = customerNo;Name;BranchCode;representive;overall
My data not coming under headers. Why I have this problem. Am I doing something wrong ?
Since your desired column names are different than the property keys you need to define them as custom:
const fields = [{
label: 'customerNo',
value: 'cNo'
}, {
label: 'Name',
value: 'name'
}, {
label: 'BranchCode',
value: 'bCode'
}, {
label: 'representive',
value: 'rps'
}, {
label: 'overall',
value: 'overall'
}
];
This is also explained in the docs -> https://github.com/zemirco/json2csv#example-3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With