json-csv-transformer
v3.0.2
Published
transform json to csv, and vice versa
Downloads
46
Maintainers
Readme
json-csv-transformer
transform json to csv, and vice versa
Install
npm install json-csv-transformer --save
Use
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
Schema
| 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