5
5
[ ![ Build Status] ( https://travis-ci.org/mrodrig/json-2-csv.svg?branch=master )] ( https://travis-ci.org/mrodrig/json-2-csv )
6
6
[ ![ Downloads] ( http://img.shields.io/npm/dm/json-2-csv.svg )] ( https://www.npmjs.org/package/json-2-csv )
7
7
[ ![ NPM version] ( https://img.shields.io/npm/v/json-2-csv.svg )] ( https://www.npmjs.org/package/json-2-csv )
8
+ [ ![ Maintainability] ( https://api.codeclimate.com/v1/badges/8c0cc3699d054fb77abe/maintainability )] ( https://codeclimate.com/github/mrodrig/json-2-csv/maintainability )
8
9
[ ![ Known Vulnerabilities] ( https://snyk.io/test/npm/json-2-csv/badge.svg )] ( https://snyk.io/test/npm/json-2-csv )
9
10
10
11
This node module will convert an array of JSON documents to a CSV string.
@@ -30,6 +31,10 @@ $ npm install json-2-csv
30
31
let converter = require (' json-2-csv' );
31
32
```
32
33
34
+ ## Upgrading?
35
+
36
+ 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 ) .
37
+
33
38
### API
34
39
35
40
#### ` converter.json2csv(array, callback, options) `
@@ -40,25 +45,22 @@ let converter = require('json-2-csv');
40
45
* ` options ` - (Optional) A JSON document specifying any of the following key value pairs:
41
46
* ` delimiter ` - Document - Specifies the different types of delimiters
42
47
* ` field ` - String - Field Delimiter.
43
- * Default: ` ',' `
44
- * ` array ` - String - Array Value Delimiter.
45
- * Default: ` ';' `
48
+ * Default: ` , `
46
49
* ` wrap ` - String - Wrap values in the delimiter of choice (e.g. wrap values in quotes).
47
- * Default: ` '' `
50
+ * Default: ` " `
48
51
* ` eol ` - String - End of Line Delimiter.
49
- * Default: ` '\n' `
52
+ * Default: ` \n `
53
+ * ` excelBOM ` - Boolean - Should a unicode character be prepended to allow Excel to open a UTF-8 encoded file with non-ASCII characters present.
50
54
* ` prependHeader ` - Boolean - Should the auto-generated header be prepended as the first line in the CSV?
51
55
* Default: ` true `
52
56
* ` sortHeader ` - Boolean - Should the header keys be sorted in alphabetical order?
53
57
* Default: ` false `
54
- * ` emptyFieldValue ` - String - Value for fields without data _ when not checking schemas_ .
55
- * Default: ` 'null' `
56
58
* ` trimHeaderFields ` - Boolean - Should the header fields be trimmed?
57
59
* Default: ` false `
58
60
* ` trimFieldValues ` - Boolean - Should the field values be trimmed? (* in development* )
59
61
* Default: ` false `
60
62
* ` checkSchemaDifferences ` - Boolean - Should all documents have the same schema?
61
- * Default: ` true `
63
+ * Default: ` false `
62
64
* Note: Change this to ` false ` if some documents are missing certain fields and you still want to convert the data.
63
65
* ` keys ` - Array - Specify the keys (as strings) that should be converted.
64
66
* Default: ` null `
@@ -69,7 +71,7 @@ let converter = require('json-2-csv');
69
71
70
72
For examples, please refer to the [ json2csv API Documentation (Link)] ( https://github.com/mrodrig/json-2-csv/wiki/json2csv-Documentation )
71
73
72
- #### Promisified Version: ` converter.json2csvPromisified (array, options) `
74
+ #### Promisified Version: ` converter.json2csvAsync (array, options) `
73
75
74
76
Available in version ` 2.2.0 ` , this functionality makes use of promises from the ` bluebird ` module.
75
77
@@ -80,13 +82,13 @@ Available in version `2.2.0`, this functionality makes use of promises from the
80
82
* ` options ` - (Optional) A JSON document specifying any of the following key value pairs:
81
83
* ` delimiter ` - Document - Specifies the different types of delimiters
82
84
* ` field ` - String - Field Delimiter.
83
- * Default: ` ',' `
84
- * ` array ` - String - Array Value Delimiter.
85
- * Default: ` ';' `
85
+ * Default: ` , `
86
86
* ` wrap ` - String - The character that field values are wrapped in.
87
- * Default: ` '' `
87
+ * Default: ` " `
88
88
* ` eol ` - String - End of Line Delimiter.
89
- * Default: ` '\n' `
89
+ * Default: ` \n `
90
+ * ` excelBOM ` - Boolean - Does the CSV contain a unicode character prepended in order to allow Excel to open a UTF-8 encoded file with non-ASCII characters present?
91
+ * Default: `false`
90
92
* ` trimHeaderFields ` - Boolean - Should the header fields be trimmed?
91
93
* Default: ` false `
92
94
* ` trimFieldValues ` - Boolean - Should the field values be trimmed?
@@ -98,7 +100,7 @@ Available in version `2.2.0`, this functionality makes use of promises from the
98
100
99
101
For examples, please refer to the [ csv2json API Documentation (Link)] ( https://github.com/mrodrig/json-2-csv/wiki/csv2json-Documentation )
100
102
101
- #### Promisified Version: ` csv2jsonPromisified (csv, options)`
103
+ #### Promisified Version: ` csv2jsonAsync (csv, options)`
102
104
103
105
Available in version ` 2.2.0 ` , this functionality makes use of promises from the ` bluebird ` module.
104
106
@@ -108,7 +110,7 @@ Available in version `2.2.0`, this functionality makes use of promises from the
108
110
$ npm test
109
111
```
110
112
111
- _ Note_ : This requires ` mocha ` , ` should ` , ` async ` , and ` underscore ` .
113
+ _ Note_ : This requires ` mocha ` , ` should ` , and ` underscore ` .
112
114
113
115
To see test coverage, please run:
114
116
``` bash
@@ -117,18 +119,18 @@ $ npm run coverage
117
119
118
120
Current Coverage is:
119
121
```
120
- Statements : 94.69 % ( 196/207 )
121
- Branches : 93.55 % ( 145/155 )
122
- Functions : 100% ( 34/34 )
123
- Lines : 95.38 % ( 186/195 )
122
+ Statements : 100 % ( 245/245 )
123
+ Branches : 100 % ( 122/122 )
124
+ Functions : 100% ( 48/48 )
125
+ Lines : 100 % ( 243/243 )
124
126
```
125
127
126
128
## Frequently Asked Questions (FAQ)
127
129
Please find the updated list (relocated to the Wiki) here: [ Frequently Asked Questions (Link)] ( https://github.com/mrodrig/json-2-csv/wiki/FAQ )
128
130
129
131
## Features
130
132
* Header Generation (per document keys)
131
- * Allows for conversion of specific keys in both json2csv and csv2json via the options.KEYS parameter (as of 1.1.2)
133
+ * Allows for conversion of specific keys in both json2csv and csv2json via the options.keys parameter (as of 1.1.2)
132
134
* Verifies all documents have same schema (schema field order does not matter as of 1.1.0)
133
135
* Supports sub-documents natively
134
136
* Supports arrays as document values for both json2csv and csv2json
@@ -138,5 +140,6 @@ Please find the updated list (relocated to the Wiki) here: [Frequently Asked Que
138
140
* Promisifiable via bluebird's .promisify(<function >) and .promisifyAll(<object >) (as of 1.1.1)
139
141
* Wrapped value support for json2csv and csv2json (as of 1.3.0)
140
142
* Support for multiple different schemas (as of 1.4.0)
141
- * Promisified versions of the functions are now available by default: json2csvPromisified, csv2jsonPromisified (as of 2.2.0)
143
+ * Promisified versions of the functions are now available by default: json2csvAsync, csv2jsonAsync (as of 2.2.0)
142
144
* Nested quotes are escaped with an additional quote (per [ RFC 4180] ( https://tools.ietf.org/html/rfc4180 ) ) thanks to @eric-thelin (as of 2.3.0)
145
+ * RFC 4180 Compliance (as of 3.0.0)
0 commit comments