kaue / jsonexport

{} → :page_facing_up: it's easy to convert JSON to CSV
http://kaue.github.io/jsonexport/
Apache License 2.0
247 stars 41 forks source link

v2.0.0 #24

Closed kaue closed 7 years ago

kaue commented 7 years ago

What's included?

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);
});

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); });