convert CSV to JSON Lines
# convert CSV file to JSON Lines
$ cj input.csv > output.jsonl
# read from stdin if no file is specified
$ cj < input.csv > output.jsonl
# specify columns to convert in A1 like notation
$ cj -s AA:AC,BC:CD input.csv > output.jsonl
download binary from releases and place it in your PATH.
-s
option is used to specify columns to convert in A1 like notation.
but unlike A1 notation, you can not specify a range of rows. (e.g. 'A1:B2' is not supported)
by using A1 like notation you can
- select single column
- e.g.
A
- e.g.
- select range of columns
- e.g.
A:C
- e.g.
- select multiple ranges of columns
- e.g.
A:C,E:G
- e.g.
in the following examples, notation is written in upper case. but it is case-insensitive.
suppose you have a CSV file like this.
A,B,C,...,Z,AA,AB,AC
0,1,2,...,25,26,27,28
You can specify single column by sequence of alphabets.
$ cj -s AA input.csv # or `cj -s aa input.csv`
["AA"]
["26"]
You can select range of columns by following notation.
$ cj -s AA:AC input.csv
["AA","AB","AC"]
["26","27","28"]
If left side of colon is larger than right side, select columns in reverse order.
$ cj -s AC:AA input.csv
["AC","AB","AA"]
["28","27","26"]
You can specify multiple ranges by separating them with comma.
$ cj -s A:B,D:E input.csv
["A","B","D","E"]
["0","1","3","4"]
overlapping ranges are supported. if then, concatenated columns are selected.
$ cj -s A:C,B:D ./input.csv
["A","B","C","B","C","D"]
["0","1","2","1","2","3"]