You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+59-64Lines changed: 59 additions & 64 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,11 +21,11 @@ $ npm install json2csv --save
21
21
Include the module and run or [use it from the Command Line](https://github.com/zemirco/json2csv#command-line-interface). It's also possible to include `json2csv` as a global using an HTML script tag, though it's normally recommended that modules are used.
22
22
23
23
```javascript
24
-
var json2csv =require('json2csv');
25
-
var fields = ['field1', 'field2', 'field3'];
24
+
constjson2csv=require('json2csv');
25
+
constfields= ['field1', 'field2', 'field3'];
26
26
27
27
try {
28
-
var result =json2csv({ data:myData, fields: fields });
28
+
constresult=json2csv(myData, { fields });
29
29
console.log(result);
30
30
} catch (err) {
31
31
// Errors are thrown for bad options, or if the data is empty and no fields are provided.
@@ -56,19 +56,17 @@ try {
56
56
### Available Options
57
57
58
58
-`options` - **Required**; Options hash.
59
-
-`data` - **Required**; Array of JSON objects.
60
59
-`fields` - Array of Objects/Strings. Defaults to toplevel JSON attributes. See example below.
61
-
-`delimiter` - String, delimiter of columns. Defaults to `,` if not specified.
60
+
-`unwind` - Array of Strings, creates multiple rows from a single JSON document similar to MongoDB's $unwind
61
+
-`flatten` - Boolean, flattens nested JSON using [flat]. Defaults to `false`.
62
62
-`defaultValue` - String, default value to use when missing data. Defaults to `<empty>` if not specified. (Overridden by `fields[].default`)
63
63
-`quote` - String, quote around cell values and column names. Defaults to `"` if not specified.
64
64
-`doubleQuote` - String, the value to replace double quote in strings. Defaults to 2x`quotes` (for example `""`) if not specified.
65
-
-`header` - Boolean, determines whether or not CSV file will contain a title column. Defaults to `true` if not specified.
65
+
-`delimiter` - String, delimiter of columns. Defaults to `,` if not specified.
66
66
-`eol` - String, overrides the default OS line ending (i.e. `\n` on Unix and `\r\n` on Windows).
67
-
-`flatten` - Boolean, flattens nested JSON using [flat]. Defaults to `false`.
68
-
-`unwind` - Array of Strings, creates multiple rows from a single JSON document similar to MongoDB's $unwind
69
67
-`excelStrings` - Boolean, converts string data into normalized Excel style data.
68
+
-`header` - Boolean, determines whether or not CSV file will contain a title column. Defaults to `true` if not specified.
70
69
-`includeEmptyRows` - Boolean, includes empty rows. Defaults to `false`.
71
-
-`preserveNewLinesInValues` - Boolean, preserve \r and \n in values. Defaults to `false`.
72
70
-`withBOM` - Boolean, with BOM character. Defaults to `false`.
73
71
74
72
#### Example `fields` option
@@ -85,11 +83,7 @@ try {
85
83
// Supports label -> derived value
86
84
{
87
85
label:'some label', // Supports duplicate labels (required, else your column will be labeled [function])
0 commit comments