← 返回命令列表

Linux command

csvjson 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Convert CSV to JSON

csvjson [data.csv]

Convert with indentation

csvjson -i [4] [data.csv]

Convert to newline-delimited JSON

csvjson --stream [data.csv]

Use a column as key

csvjson -k [id] [data.csv]

Convert to GeoJSON

csvjson --lat [latitude] --lon [longitude] [data.csv]

Convert with custom delimiter

csvjson -d "[;]" [data.csv]

Convert from stdin

cat [data.csv] | csvjson

Disable type inference

csvjson --no-inference [data.csv]

说明

csvjson is part of csvkit that converts CSV files to JSON format. It supports various output formats including JSON arrays, keyed objects, newline-delimited JSON for streaming, and GeoJSON for geographic data. By default, output is a JSON array of objects where each row becomes an object with column names as keys. The -k option creates a keyed object using a unique column's values as keys. Type inference converts numeric and boolean values appropriately. The streaming mode outputs one JSON object per line, suitable for processing with tools like jq or for large files that shouldn't be loaded entirely.

参数

-i _N_, --indent _N_
Indentation level for pretty printing.
-k _COLUMN_, --key _COLUMN_
Column to use as object keys (creates object instead of array).
--stream
Output newline-delimited JSON (one object per line).
--lat _COLUMN_
Latitude column for GeoJSON output.
--lon _COLUMN_
Longitude column for GeoJSON output.
-d _CHAR_, --delimiter _CHAR_
Field delimiter (default: comma).
-e _ENCODING_, --encoding _ENCODING_
Input file encoding.
--no-inference
Disable type inference (keep all values as strings).
-H, --no-header-row
Treat file as having no header row; columns are labeled a, b, c, etc.
--snifflimit _N_
Limit CSV dialect sniffing to N bytes (0 to disable).

FAQ

What is the csvjson command used for?

csvjson is part of csvkit that converts CSV files to JSON format. It supports various output formats including JSON arrays, keyed objects, newline-delimited JSON for streaming, and GeoJSON for geographic data. By default, output is a JSON array of objects where each row becomes an object with column names as keys. The -k option creates a keyed object using a unique column's values as keys. Type inference converts numeric and boolean values appropriately. The streaming mode outputs one JSON object per line, suitable for processing with tools like jq or for large files that shouldn't be loaded entirely.

How do I run a basic csvjson example?

Run `csvjson [data.csv]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -i _N_, --indent _N_ do in csvjson?

Indentation level for pretty printing.