Closed Neats29 closed 7 years ago
Thanks for creating this module. I thought that the role of the fields option is so that you can give different names to the headings but it doesn't work if the field names don't match the property names. For example:
fields
var fields = ['cars', 'prices', 'colors']; var myCars = [ { "car": "Audi", "price": 40000, "color": "blue" }, { "car": "BMW", "price": 35000, "color": "black" }, { "car": "Porsche", "price": 60000, "color": "green" } ]; json2csv({ data: myCars, fields: fields }, (err, csv) => console.log(csv)); returns: "cars","prices","colors" ,, ,, ,,
Is this the expected behaviour? Seems a bit odd that you wouldn't be able to change the names if there is a fields option.
You must use the object format of fields, see https://github.com/zemirco/json2csv#example-fields-option
@knownasilya that worked, thank you 👍
Thanks for creating this module. I thought that the role of the
fields
option is so that you can give different names to the headings but it doesn't work if the field names don't match the property names. For example:Is this the expected behaviour? Seems a bit odd that you wouldn't be able to change the names if there is a
fields
option.