Here is a nice example on how to convert a complete json to csv.
I installed the program using npm install json-2-csv
I tried to take a run at the example. I made a js file but I can't run it. How can I run it to see in action how it works?
It is the example provided for json-2-csv page.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title> </title>
</head>
<body>
<script>
var converter = require('json-2-csv');
var documents = [
{
Make: 'Nissan',
Model: 'Murano',
Year: '2013',
Specifications: {
Mileage: '7106',
Trim: 'S AWD'
}
},
{
Make: 'BMW',
Model: 'X5',
Year: '2014',
Specifications: {
Mileage: '3287',
Trim: 'M'
}
}
];
var json2csvCallback = function (err, csv) {
if (err) throw err;
console.log(csv);
};
converter.json2csv(documents, json2csvCallback);
</script>
</body>
</html>