Complete command-line tool for CSV to JSON conversion with extensive options, flexible input/output handling, and example usage patterns for common data processing tasks.
Command-line interface for converting CSV files to JSON format.
# Basic conversion
csvtojson [options] <input_file>
# Output to file
csvtojson [options] <input_file> > output.json
# Read from stdin
cat input.csv | csvtojson [options]
# Help information
csvtojson --helpUsage Examples:
# Convert CSV file to JSON
csvtojson data.csv
# Convert and save to file
csvtojson data.csv > output.json
# Process from stdin
cat data.csv | csvtojson > output.json
# Process multiple files (shell expansion)
for file in *.csv; do
csvtojson "$file" > "${file%.csv}.json"
doneConfigure CSV delimiter detection and specification.
# Auto-detect delimiter
csvtojson --delimiter=auto input.csv
# Specify delimiter
csvtojson --delimiter=";" input.csv
csvtojson --delimiter="|" input.csv
csvtojson --delimiter=$'\t' input.csv # Tab delimiter
# Quote character
csvtojson --quote="'" input.csvUsage Examples:
# European CSV format (semicolon delimiter)
csvtojson --delimiter=";" --quote='"' european-data.csv
# Tab-separated values
csvtojson --delimiter=$'\t' data.tsv
# Pipe-delimited with custom quote
csvtojson --delimiter="|" --quote="'" pipe-data.csv
# Auto-detect delimiter from file
csvtojson --delimiter=auto unknown-format.csvControl header handling and column processing.
# No header row (first row is data)
csvtojson --noheader input.csv
# Custom headers
csvtojson --headers="id,name,email,age" input.csv
# Ignore specific columns
csvtojson --ignoreColumns="/password|ssn/" input.csv
# Include only specific columns
csvtojson --includeColumns="/id|name|email/" input.csvUsage Examples:
# Process headerless CSV with custom headers
csvtojson --noheader --headers="product_id,product_name,price,quantity" inventory.csv
# Remove sensitive information
csvtojson --ignoreColumns="/password|ssn|credit_card/" user-data.csv
# Extract specific fields only
csvtojson --includeColumns="/^(id|timestamp|value)$/" sensor-data.csv
# Process CSV with mixed case headers
csvtojson --trim --headers="ID,Full_Name,Email_Address,Phone_Number" contact-list.csvConfigure data parsing and type conversion.
# Enable type detection and conversion
csvtojson --checkType input.csv
# Trim whitespace from values
csvtojson --trim input.csv
# Treat dots and brackets as literal characters
csvtojson --flatKeys input.csv
# Convert "null" strings to null values
csvtojson --nullObject input.csvUsage Examples:
# Full data processing pipeline
csvtojson \
--checkType \
--trim \
--nullObject \
--ignoreEmpty \
sales-data.csv
# Preserve nested structure
csvtojson --checkType user-profiles.csv
# Flat output (no nested objects)
csvtojson --flatKeys --trim config-data.csv
# Type conversion with validation
csvtojson --checkType --checkColumn financial-data.csvControl output formatting and structure.
# Output as CSV array format
csvtojson --output=csv input.csv
# Output as line-delimited JSON
csvtojson --output=line input.csv
# Default JSON object array
csvtojson --output=json input.csv
# Pretty-print JSON output
csvtojson input.csv | jq '.'Usage Examples:
# Convert to JSON array format
csvtojson --output=json data.csv | jq '.'
# Convert to CSV array (for validation)
csvtojson --output=csv data.csv
# Line-delimited JSON for streaming
csvtojson --output=line large-data.csv | head -10
# Combine with jq for advanced processing
csvtojson data.csv | jq '.[] | select(.age > 25)'
# Format for specific tools
csvtojson --output=line data.csv | mongoimport --collection usersAdvanced parsing options for complex CSV files.
# Maximum row length (prevent memory issues)
csvtojson --maxRowLength=10000 input.csv
# Validate column count consistency
csvtojson --checkColumn input.csv
# Always split at line endings (no multiline cells)
csvtojson --alwaysSplitAtEOL input.csv
# Custom end-of-line character
csvtojson --eol="\r\n" windows-file.csvUsage Examples:
# Safe parsing of untrusted data
csvtojson \
--maxRowLength=65535 \
--checkColumn \
--alwaysSplitAtEOL \
--trim \
untrusted-data.csv
# Process Windows-formatted files on Unix
csvtojson --eol=$'\r\n' --trim windows-export.csv
# Strict validation for data quality
csvtojson \
--checkColumn \
--checkType \
--maxRowLength=50000 \
quality-controlled-data.csvHandle errors and validation issues during processing.
# Show verbose error information
csvtojson --verbose input.csv
# Continue processing despite errors (if supported)
csvtojson --ignoreErrors input.csv 2>errors.log
# Validate before processing
csvtojson --checkColumn --maxRowLength=10000 input.csvUsage Examples:
# Process with error logging
csvtojson --checkColumn data.csv 2>parse-errors.log 1>output.json
# Validate file structure first
csvtojson --checkColumn --maxRowLength=1000 test-data.csv >/dev/null
# Robust processing with fallback
csvtojson --trim --ignoreEmpty data.csv || \
csvtojson --delimiter=auto --trim data.csv || \
echo "Failed to parse CSV file"
# Check file before processing
if csvtojson --checkColumn data.csv >/dev/null 2>&1; then
echo "File structure is valid"
csvtojson --checkType --trim data.csv > output.json
else
echo "File has structure issues"
fiIntegration with Unix pipelines and other tools.
# Integration with curl and APIs
curl -s "https://api.example.com/data.csv" | csvtojson | jq '.'
# Integration with database tools
csvtojson --output=line data.csv | mongoimport --collection mydata
# Integration with file processing
find . -name "*.csv" -exec csvtojson {} \; | jq -s '.'Usage Examples:
# Download and process CSV from web
curl -s "https://data.gov/export.csv" | \
csvtojson --checkType --trim | \
jq '.[] | select(.population > 100000)'
# Batch process multiple files
for file in data/*.csv; do
echo "Processing $file..."
csvtojson --checkType "$file" > "json/$(basename "$file" .csv).json"
done
# Stream processing with monitoring
csvtojson --output=line large-dataset.csv | \
while IFS= read -r line; do
echo "$line" | jq '.id' >> processed-ids.txt
# Process each record individually
done
# Integration with data validation
csvtojson data.csv | \
jq '.[] | select(.email | test("@.+\\..+"))' | \
jq -s '.' > valid-emails.json
# ETL pipeline example
csvtojson --checkType --trim source-data.csv | \
jq 'map({
id: .id | tonumber,
name: .name | ascii_upcase,
email: .email | ascii_downcase,
created: now | strftime("%Y-%m-%d")
})' > transformed-data.jsonOptions for optimizing performance with large files.
# Process large files efficiently
csvtojson --output=line --maxRowLength=100000 large-file.csv
# Memory-efficient streaming
csvtojson large-file.csv | jq -c '.[]' > output.jsonl
# Parallel processing (with GNU parallel)
parallel -j4 csvtojson {} ::: *.csvUsage Examples:
# Memory-efficient processing of large files
csvtojson --output=line --maxRowLength=50000 big-data.csv | \
split -l 10000 - processed-chunk-
# Parallel processing multiple files
ls *.csv | parallel -j$(nproc) 'csvtojson --checkType {} > {.}.json'
# Chunked processing with progress
total_lines=$(wc -l < large-file.csv)
csvtojson --output=line large-file.csv | \
pv -l -s $total_lines | \
split -l 50000 - chunk-
# Stream processing without memory accumulation
mkfifo csv_pipe
csvtojson --output=line input.csv > csv_pipe &
while IFS= read -r line < csv_pipe; do
# Process each line individually
echo "$line" | jq '.id'
done