-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: In the JavaScript modules, `formatters` are introduced and the `quote`, `escapedQuote` and `excelStrings` options are removed. See the migration notes in the readme. CLI hasn't changed.
- Loading branch information
1 parent
7ade321
commit 88ed6ee
Showing
36 changed files
with
2,238 additions
and
1,376 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
"es6": true | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": 8 | ||
"ecmaVersion": 9 | ||
}, | ||
"extends": "eslint:recommended" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# CLI examples | ||
|
||
All examples use this example [input file](https://github.com/zemirco/json2csv/blob/master/test/fixtures/json/default.json). | ||
|
||
## Input file and specify fields | ||
|
||
```sh | ||
$ json2csv -i input.json -f carModel,price,color | ||
carModel,price,color | ||
"Audi",10000,"blue" | ||
"BMW",15000,"red" | ||
"Mercedes",20000,"yellow" | ||
"Porsche",30000,"green" | ||
``` | ||
|
||
## Input file, specify fields and use pretty logging | ||
|
||
```sh | ||
$ json2csv -i input.json -f carModel,price,color -p | ||
``` | ||
|
||
![Screenshot](https://s3.amazonaws.com/zeMirco/github/json2csv/json2csv-pretty.png) | ||
|
||
## Generating CSV containing only specific fields | ||
|
||
```sh | ||
$ json2csv -i input.json -f carModel,price,color -o out.csv | ||
$ cat out.csv | ||
carModel,price,color | ||
"Audi",10000,"blue" | ||
"BMW",15000,"red" | ||
"Mercedes",20000,"yellow" | ||
"Porsche",30000,"green" | ||
``` | ||
|
||
Same result will be obtained passing the fields config as a file. | ||
|
||
```sh | ||
$ json2csv -i input.json -c fieldsConfig.json -o out.csv | ||
``` | ||
|
||
where the file `fieldsConfig.json` contains | ||
|
||
```json | ||
[ | ||
"carModel", | ||
"price", | ||
"color" | ||
] | ||
``` | ||
|
||
## Read input from stdin | ||
|
||
```sh | ||
$ json2csv -f price | ||
[{"price":1000},{"price":2000}] | ||
``` | ||
|
||
Hit <kbd>Enter</kbd> and afterwards <kbd>CTRL</kbd> + <kbd>D</kbd> to end reading from stdin. The terminal should show | ||
|
||
```sh | ||
price | ||
1000 | ||
2000 | ||
``` | ||
|
||
## Appending to existing CSV | ||
|
||
Sometimes you want to add some additional rows with the same columns. | ||
This is how you can do that. | ||
|
||
```sh | ||
# Initial creation of csv with headings | ||
$ json2csv -i test.json -f name,version > test.csv | ||
# Append additional rows | ||
$ json2csv -i test.json -f name,version --no-header >> test.csv | ||
``` |
Oops, something went wrong.