I\'m currently learning how to parse a JSON object to a CSV file using the json2csv node module. Have never worked with JSON before, so this is all new to me.
My JSO
You can also direct json2csv to use a sub array within your JSON object by addressing it with .
after your JSON object in the data section of json2csv.
In your case, this might look something like:
const json2csv = require('json2csv');
const fs = require('fs');
var json = {
"car":[
{
"name":"Audi",
"price":"40000",
"color":"blue"
}
]
};
json2csv({data: json.car, fields: ['name', 'price', 'color']}, function(err, csv) {
if (err) console.log(err);
fs.writeFile('cars.csv', csv, function(err) {
if (err) throw err;
console.log('cars file saved');
});
});