zemirco / json2csv

Convert json to csv with column titles
http://zemirco.github.io/json2csv
MIT License
2.71k stars 365 forks source link

Error: params should include "fields" and/or non-empty "data" array of objects #250

Closed udanpe closed 6 years ago

udanpe commented 6 years ago

copy\paste example and Error.. node 4,6,8 macos

const json2csv = require('json2csv');
const fs = require('fs');
const fields = ['car', 'price', 'color'];
const myCars = [
  {
    "car": "Audi",
    "price": 40000,
    "color": "blue"
  }, {
    "car": "BMW",
    "price": 35000,
    "color": "black"
  }, {
    "car": "Porsche",
    "price": 60000,
    "color": "green"
  }
];
const csv = json2csv(myCars, { fields });

console.log(csv);
juanjoDiaz commented 6 years ago

The documentation in Github is for the next release, 4.0, which will introduce a lot of changes and goodness.

For the current release, you should follow the instructions in npm.

The main change is that instead of const csv = json2csv(myCars, { fields }); you should do const csv = json2csv({ data: myCars, fields });

juanjoDiaz commented 6 years ago

@udanpe please confirm if that was your issue.

shierro commented 6 years ago

just used the library & const csv = json2csv({ data: myCars, fields }); helped. thanks mate!

juanjoDiaz commented 6 years ago

I'll keep this open until the 4.0 release in case anyone else gets into the same confusion.

udanpe commented 6 years ago

@juanjoDiaz const csv = json2csv({ data: myCars, fields }); Its works. Thanks.

udanpe commented 6 years ago

UPD. docs https://github.com/zemirco/json2csv/blob/new-api/README.md

knownasilya commented 6 years ago

v4.0.0 released