1 | # csv2json
|
2 |
|
3 | [![Package Version](https://badgen.net/npm/v/csv2json)](https://npmjs.org/package/csv2json) [![Build Status](https://travis-ci.org/julien-f/csv2json.png?branch=master)](https://travis-ci.org/julien-f/csv2json) [![PackagePhobia](https://badgen.net/packagephobia/install/csv2json)](https://packagephobia.now.sh/result?p=csv2json) [![Latest Commit](https://badgen.net/github/last-commit/julien-f/csv2json)](https://github.com/julien-f/csv2json/commits/master)
|
4 |
|
5 | > Stream and CLI to convert CSV to JSON.
|
6 |
|
7 | ## Install
|
8 |
|
9 | Installation of the [npm package](https://npmjs.org/package/csv2json):
|
10 |
|
11 | Install globally if you want to use the CLI:
|
12 |
|
13 | ```
|
14 | npm install --global csv2json
|
15 | ```
|
16 |
|
17 | Install locally if you want to use it as a library:
|
18 |
|
19 | ```
|
20 | npm install --save csv2json
|
21 | ```
|
22 |
|
23 | ## Usage
|
24 |
|
25 | ### CLI
|
26 |
|
27 | ```
|
28 | Usage: csv2json [OPTIONS] [<input file> [<output file>]]
|
29 |
|
30 | -d, --dynamic-typing
|
31 | Convert booleans and numeric to their type instead of strings.
|
32 |
|
33 | -s <separator>, --separator=<separator>
|
34 | Field separator to use (default to comma “,”).
|
35 |
|
36 | -t, --tsv
|
37 | Use tab as separator, overrides separator flag.
|
38 |
|
39 | <input file>
|
40 | CSV file to read data from.
|
41 | If unspecified or a dash (“-”), use the standard input.
|
42 |
|
43 | <output file>
|
44 | JSON file to write data to.
|
45 | If unspecified or a dash (“-”), use the standard output.
|
46 | ```
|
47 |
|
48 | ### Stream
|
49 |
|
50 | ```javascript
|
51 | var csv2json = require('csv2json');
|
52 | var fs = require('fs');
|
53 |
|
54 | fs.createReadStream('data.csv')
|
55 | .pipe(csv2json({
|
56 | // Defaults to comma.
|
57 | separator: ';'
|
58 | }))
|
59 | .pipe(fs.createWriteStream('data.json'));
|
60 | ```
|
61 |
|
62 | ## Contributions
|
63 |
|
64 | Contributions are *very* welcomed, either on the documentation or on
|
65 | the code.
|
66 |
|
67 | You may:
|
68 |
|
69 | - report any [issue](https://github.com/julien-f/csv2json/issues)
|
70 | you've encountered;
|
71 | - fork and create a pull request.
|
72 |
|
73 | ## Note
|
74 |
|
75 | Thanks to @twilson63 for letting me use the *csv2json* name on [npm](https://www.npmjs.org/).
|
76 |
|
77 | ## License
|
78 |
|
79 | ISC © [Julien Fontanet](http://julien.isonoe.net)
|