Closed kaue closed 7 years ago
var jsonexport = require('jsonexport'); var fs = require('fs');
var reader = fs.createReadStream('data.json'); var writer = fs.createWriteStream('out.csv');
reader.pipe(jsonexport()).pipe(writer);
- `fillGaps` option https://github.com/kauegimenes/jsonexport/commit/7270f4873ba8e7fa87027ce52546c08122d7aaef https://github.com/kauegimenes/jsonexport/issues/22 ```javascript var jsonexport = require('jsonexport'); var students = [ { "name" : "John", "clases" : [ { "year" : 2016, "grade" : "1st", "payment":[ { "type":"monthly", "status":"done" }, { "type":"yearly", "status":"done" } ] }, { "year" : 2017, "grade" : "2nd", "payment":[ { "type":"monthly", "status":"in progress" }, { "type":"yearly", "status":"done" } ] } ], }, { "name" : "Andrew", "clases" : [ { "year" : 2017, "grade" : "1nd", "payment":[ { "type":"monthly", "status":"in progress" }, { "type":"yearly", "status":"in progress" } ] } ] }, ] jsonexport(students, { fillGaps: true }, function(err, csv){ if(err) return console.log(err); console.log(csv); });
headers
var jsonexport = require('jsonexport');
var contacts = [{ name: 'Bob', lastname: 'Smith', address: { number: 1 } },{ name: 'James', lastname: 'David' },{ name: 'Robert', lastname: 'Miller' },{ name: 'David', lastname: 'Martin' }];
jsonexport(contacts, { headers: ['lastname', 'name', 'address.number'] },function(err, csv){ if(err) return console.log(err); console.log(csv); });
What's included?
var reader = fs.createReadStream('data.json'); var writer = fs.createWriteStream('out.csv');
reader.pipe(jsonexport()).pipe(writer);
headers
option https://github.com/kauegimenes/jsonexport/issues/23var contacts = [{ name: 'Bob', lastname: 'Smith', address: { number: 1 } },{ name: 'James', lastname: 'David' },{ name: 'Robert', lastname: 'Miller' },{ name: 'David', lastname: 'Martin' }];
jsonexport(contacts, { headers: ['lastname', 'name', 'address.number'] },function(err, csv){ if(err) return console.log(err); console.log(csv); });