1
1
# json-2-csv
2
2
** Convert JSON to CSV _ or_ CSV to JSON**
3
3
4
- [ ![ Dependencies] ( https://img.shields.io/librariesio/release/npm/json-2-csv )] ( https://www.npmjs.org/package/json-2-csv )
5
- [ ![ Downloads] ( https://img.shields.io/npm/dm/json-2-csv.svg )] ( https://www.npmjs.org/package/json-2-csv )
6
4
[ ![ NPM version] ( https://img.shields.io/npm/v/json-2-csv.svg )] ( https://www.npmjs.org/package/json-2-csv )
5
+ [ ![ Typings] ( https://img.shields.io/npm/types/json-2-csv )] ( https://www.npmjs.org/package/json-2-csv )
6
+ [ ![ Downloads] ( https://img.shields.io/npm/dm/json-2-csv.svg )] ( https://www.npmjs.org/package/json-2-csv )
7
7
[ ![ Minzipped Size] ( https://img.shields.io/bundlephobia/minzip/json-2-csv )] ( https://bundlephobia.com/result?p=json-2-csv )
8
8
9
9
[ ![ Build Status] ( https://travis-ci.org/mrodrig/json-2-csv.svg?branch=master )] ( https://travis-ci.org/mrodrig/json-2-csv )
10
10
[ ![ Coverage Status] ( https://coveralls.io/repos/github/mrodrig/json-2-csv/badge.svg?branch=stable )] ( https://coveralls.io/github/mrodrig/json-2-csv?branch=stable )
11
11
[ ![ Maintainability] ( https://api.codeclimate.com/v1/badges/8c0cc3699d054fb77abe/maintainability )] ( https://codeclimate.com/github/mrodrig/json-2-csv/maintainability )
12
- [ ![ Typings] ( https://img.shields.io/npm/types/json-2-csv )] ( https://www.npmjs.org/package/json-2-csv )
13
12
14
13
This node module will convert an array of JSON documents to a CSV string.
15
14
Column headings will be automatically generated based on the keys of the JSON documents. Nested documents will have a '.' appended between the keys.
@@ -30,12 +29,13 @@ $ npm install @mrodrig/json-2-csv-cli
30
29
31
30
## Upgrading?
32
31
33
- Upgrading to v3 from v2 ? Check out the [ upgrade guide] ( https://github.com/mrodrig/json-2-csv/blob/master/upgrade_guides/UPGRADE_2_to_3 .md ) .
32
+ Upgrading to v4 from v3 ? Check out the [ upgrade guide] ( https://github.com/mrodrig/json-2-csv/blob/master/upgrade_guides/UPGRADE_3_to_4 .md ) .
34
33
35
34
## Usage
36
35
37
36
``` javascript
38
37
let converter = require (' json-2-csv' );
38
+ const csv = await converter .json2csv (data, options);
39
39
```
40
40
or
41
41
``` javascript
@@ -45,11 +45,9 @@ Looking for examples? Check out the Wiki: [json-2-csv Wiki](https://github.com/m
45
45
46
46
### API
47
47
48
- #### ` converter. json2csv(array, callback , options)`
48
+ #### ` json2csv(array, options) `
49
49
50
50
* ` array ` - An array of JSON documents to be converted to CSV.
51
- * ` callback ` - A function of the form ` function (err, csv) ` ;
52
- * This function will receive any errors and/or the string of CSV generated.
53
51
* ` options ` - (Optional) A JSON document specifying any of the following key value pairs:
54
52
* ` checkSchemaDifferences ` - Boolean - Should all documents have the same schema?
55
53
* Default: ` false `
@@ -146,14 +144,9 @@ Looking for examples? Check out the Wiki: [json-2-csv Wiki](https://github.com/m
146
144
147
145
For examples, please refer to the [json2csv API Documentation (Link)](https://github.com/mrodrig/json-2-csv/wiki/json2csv-Documentation)
148
146
149
- #### Promisified Version: `converter.json2csvAsync(array, options)`
150
-
151
- Available in version `2.2.0`, this functionality makes use of promises from the `bluebird` module.
152
-
153
- #### `converter.csv2json(csv, callback, options)`
147
+ #### `csv2json(csv, options)`
154
148
155
149
* `csv` - A string of CSV
156
- * `callback` - A function of the form `function (err, array)`; This function will receive any errors and/or the array of JSON documents generated.
157
150
* `options` - (Optional) A JSON document specifying any of the following key value pairs:
158
151
* `delimiter` - Document - Specifies the different types of delimiters
159
152
* `field` - String - Field Delimiter.
@@ -181,10 +174,6 @@ Available in version `2.2.0`, this functionality makes use of promises from the
181
174
182
175
For examples, please refer to the [csv2json API Documentation (Link)](https://github.com/mrodrig/json-2-csv/wiki/csv2json-Documentation)
183
176
184
- #### Promisified Version: `csv2jsonAsync(csv, options)`
185
-
186
- Available in version `2.2.0`, this functionality makes use of promises from the `bluebird` module.
187
-
188
177
### CLI
189
178
Note: As of `3.5.8`, the command line interface functionality has been pulled out to a separate package. Please be sure to
190
179
install the `@mrodrig/json-2-csv-cli` NPM package if you wish to use the CLI functionality shown below:
@@ -244,14 +233,6 @@ To see test coverage, please run:
244
233
$ npm run coverage
245
234
```
246
235
247
- Current Coverage is:
248
- ```
249
- Statements : 100% ( 286/286 )
250
- Branches : 100% ( 166/166 )
251
- Functions : 100% ( 73/73 )
252
- Lines : 100% ( 280/280 )
253
- ```
254
-
255
236
## Frequently Asked Questions (FAQ)
256
237
Please find the updated list (relocated to the Wiki) here: [ Frequently Asked Questions (Link)] ( https://github.com/mrodrig/json-2-csv/wiki/FAQ )
257
238
0 commit comments