csvjson
Convert CSV data to JSON
SYNOPSIS
csvjson [options] [FILE]
PARAMETERS
-d DELIM, --delimiter DELIM
Delimiter for input CSV (default: ,)
-q CHAR, --quotechar CHAR
Quote character for fields (default: ")
-u CHAR, --escapechar CHAR
Escape character in quoted fields
-z N, --maxfieldsize N
Max field length in bytes (default: unlimited)
-e ENC, --encoding ENC
Input file encoding (default: UTF-8)
-L, --lax-quotes
Allow quotes inside quoted fields
-N, --no-inference
Disable type inference; treat as strings
-H, --no-header-row
Input has no header row
-S, --skipinitialspace
Ignore spaces after delimiter
-v, --verbose
Print progress details
--indent N
JSON indentation spaces (default: 4)
--stream
Stream NDJSON (one object per line)
-k KEY, --key KEY
Key records by field name (implies --stream)
-h, --help
Show help
--version
Show version info
DESCRIPTION
csvjson is a command-line utility from the csvkit suite that transforms CSV data into JSON. It parses CSV input from a file or stdin, treating the first row as headers to create keys for JSON objects in an array. This enables seamless integration with JSON tools like jq, databases, or web services.
Core functionality includes delimiter customization, quote/escape handling, encoding support (UTF-8 default), and type inference for numbers/dates. For massive files, --stream outputs newline-delimited JSON (NDJSON) for low-memory processing. --indent pretty-prints with specified spaces, while --key indexes records by a field (with streaming).
Robust parsing covers lax quotes, no headers (-H), skipped spaces (-S), and field size limits. Verbose mode (-v) aids debugging. Ideal for ETL pipelines: cat data.csv | csvjson --stream | jq 'map(select(.price > 100))' | csvjson --dict > output.json.
Not a core Linux utility; install via pip install csvkit or distro packages (e.g., apt install csvkit). Supports Python 3, cross-platform.
CAVEATS
Requires csvkit installation; not in core Linux. Large files need --stream to avoid OOM. Assumes UTF-8 unless specified. No output file option; use redirection.
EXAMPLES
csvjson data.csv
Pretty JSON array.
csvjson -d ';' data.csv --stream
Streamed JSON from semicolon CSV.
csvjson --key id --indent 2 large.csv > output.json
Keyed, indented output.
HISTORY
Introduced in csvkit 0.9 (2011) by Christopher Groskopf to fill JSON conversion gap. Evolved with Python 3 support, streaming in 1.0 (2017). Current v2.0+ maintained by polyglot community; widely used in data science.


