user2848031 user2848031 - 1 year ago 124
Javascript Question

How to export csv file from json array using nodejs?

How to export json array to csv file in node js ? Below is format of json data which need to convert to csv file. Please advise.

I want to display only three column of values from json data. Column A : total number of response , Column B : Name , Column C : field1

Here is my code :

var json2csv = require('json2csv');
var fields = ['total', ''];
var csv = json2csv({ data: data, fields: fields });

fs.writeFile('file.csv', csv, function(err) {
if (err) throw err;
console.log('file saved');

Using this code i got total but name column coming as empty.
Columns name are:
total , name , field1

"val":"test value1",

**"val":"test value2 ",


"val":"test description",






Answer Source

You need to do the rest here is some further hint

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download