transform json to csv, and vice versa
npm install json-csv-transformer --save
import CSV from 'json-csv-transformer'
const csv = new CSV({
schema: [{
key: 'xxx',
label: 'XXX',
type: 'string',
}]
})
// parse data, csv or json
csv.parse(data)
// get file dataURL
csv.getDataURL()
// transform to JSON
csv.toJSON()
find more use case, please see test
field | type | required | description |
---|---|---|---|
key |
string |
true |
key for this schema |
label |
string |
false |
it will display in the header |
type |
string | boolean | date | number |
false |
default type is string , it will be ignored if formatter is present |
formatter |
{csv: function, json: function} |
false |
custom formatter, csv for transform to csv , json for transform to json |