A command-line utility for serializing CSV/TSV files into readable JSON format.
CSVJSON converts comma-separated values (CSV) and tab-separated values (TSV) files into JSON format, providing flexible options for output formatting and data processing.
- Convert CSV/TSV files to JSON
- Type definitions for JSON keys
- Show shared keys given multiple files
- Customizable delimiters for various file formats
- Line-based processing with offset support
- Multiple output formats (pretty-printed JSON or JSONL)
Prints help info
# read type options
all | key | type | fieldDefaults to all
# prints all key value pairs for all lines in csv
cat input.csv | csvjson -r all
# prints first set of key value pairs
cat input.csv | csvjson -r all -l 1
# prints only the 50th set of key value pairs
cat input.csv | csvjson -r all -l 1 -o 50# prints all possible types for each key value
cat input.csv | csvjson -r type# finds all shared keys for all csvs in current directory
csvjson -r key -f ./*.csv
# finds all keys which at least 5 files share in common
csvjson -r key -f ./*.csv -l 5
# finds all keys
csvjson -r key -f ./*.csv -l 1# prints all files that are missing the header "Title"
csvjson -r field -n "Title" -f ./*.csv
# prints all files that are missing the headers "Title" or "Artist"
csvjson -r field -n "Title" "Artist" -f ./*.csvSet the delimiter/separator for the input file.
Examples:
- CSV:
-s ',' - TSV:
-s $'\t'
bash
cat input.csv | csvjson -s ','
cat input.tsv | csvjson -s $'\t'Set the total number of lines to read from the input file.
bash
# read only first 100 lines
cat input.csv | csvjson -l=100 Set the offset for which line to start reading from.
bash
# skip first 10 lines
cat input.csv | csvjson -o=10Output JSONL (JSON Lines) format instead of pretty-printed JSON. Each line contains a separate JSON object.
bash
# print minimized jsonl
cat input.csv | csvjson -mbash
cat input.csv | csvjsonbash
input.tsv | csvjson -r type -s $'\t'bash
# lines 50-150 as JSONL
cat data.csv | csvjson -o 50 -l 100 -m [
{
"name": "John Doe",
"favorite_color": null,
"languages": ["French", "English"],
"age": 30,
"email": "john@example.com"
},
{
"name": "Jane Smith",
"favorite_color": "blue",
"languages": ["English"],
"age": 25,
"email": "jane@example.com"
}
]{"name":"John Doe","favorite_color":null,"languages":["French","English"],"age":30,"email":"john@example.com"}
{"name":"Jane Smith","favorite_color":"blue","languages":["English"],"age":25,"email":"jane@example.com"}{
"name": "String",
"favorite_color": "Null | String",
"languages": "Array of String",
"age": "Int",
"email": "String"
}