Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kagawagao/json-csv-transformer
transform json to csv, and vice versa
https://github.com/kagawagao/json-csv-transformer
csv csv-parser csv2json json json-parser json2csv
Last synced: 3 months ago
JSON representation
transform json to csv, and vice versa
- Host: GitHub
- URL: https://github.com/kagawagao/json-csv-transformer
- Owner: kagawagao
- License: mit
- Created: 2018-05-14T06:16:17.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-01T22:36:57.000Z (almost 2 years ago)
- Last Synced: 2024-10-07T19:38:01.891Z (3 months ago)
- Topics: csv, csv-parser, csv2json, json, json-parser, json2csv
- Language: JavaScript
- Homepage:
- Size: 1.63 MB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# json-csv-transformer
> transform json to csv, and vice versa
[![node](https://img.shields.io/node/v/json-csv-transformer.svg)](https://www.npmjs.com/package/json-csv-transformer)
[![npm](https://img.shields.io/npm/v/json-csv-transformer.svg)](https://www.npmjs.com/package/json-csv-transformer)
[![license](https://img.shields.io/npm/l/json-csv-transformer.svg)](https://github.com/kagawagao/json-csv-transformer/blob/master/LICENSE)
[![Build Status](https://travis-ci.org/kagawagao/json-csv-transformer.svg?branch=master)](https://travis-ci.org/kagawagao/json-csv-transformer)
[![Standard - JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](http://standardjs.com/)
[![Coveralls Status](https://img.shields.io/coveralls/github/kagawagao/json-csv-transformer.svg)](https://coveralls.io/github/kagawagao/json-csv-transformer)## Install
```bash
npm install json-csv-transformer --save
```## Use
```javascript
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`