| Crates.io | ctj |
| lib.rs | ctj |
| version | 0.1.8 |
| created_at | 2025-07-16 11:15:09.848668+00 |
| updated_at | 2025-07-17 11:23:35.406161+00 |
| description | A command-line tool to convert CSV to JSON written in Rust |
| homepage | |
| repository | https://github.com/lef237/ctj |
| max_upload_size | |
| id | 1755318 |
| size | 60,888 |
A command-line tool to convert CSV files to JSON format, supporting both file input and piped stdin.
cat file.csv | ctj)cargo install ctj
This will install the latest version from crates.io. After installation, you can use ctj command directly from anywhere.
Clone the repository and install locally:
git clone https://github.com/lef237/ctj.git
cd ctj
cargo install --path .
git clone https://github.com/lef237/ctj.git
cd ctj
cargo build --release
This creates an executable at ./target/release/ctj.
Convert CSV to JSON and output to stdout:
ctj input.csv
Or using the explicit flag:
ctj -i input.csv
You can also pipe CSV data directly to ctj:
cat input.csv | ctj
echo "name,age\nJohn,30" | ctj
curl https://example.com/data.csv | ctj
Format JSON output with indentation:
ctj input.csv -p
Save JSON output to a file:
ctj input.csv -o output.json
-i, --input <FILE>: Input CSV file (optional, can also be provided as positional argument; if not provided, reads from stdin)-o, --output <FILE>: Output JSON file (optional, defaults to stdout)-p, --pretty: Pretty print JSON output-n, --no-header: Treat the first row as data, not headers (generates column_0, column_1, etc.)-h, --help: Show help message-V, --version: Show version informationGiven a CSV file sample.csv:
name,age,city,active
John,25,Tokyo,true
Alice,30,Osaka,false
Bob,35,Kyoto,true
ctj sample.csv
Output:
[{"name":"John","age":25,"city":"Tokyo","active":true},{"name":"Alice","age":30,"city":"Osaka","active":false},{"name":"Bob","age":35,"city":"Kyoto","active":true}]
ctj sample.csv -p
Output:
[
{
"name": "John",
"age": 25,
"city": "Tokyo",
"active": true
},
{
"name": "Alice",
"age": 30,
"city": "Osaka",
"active": false
},
{
"name": "Bob",
"age": 35,
"city": "Kyoto",
"active": true
}
]
For CSV files without header rows, use the -n option to generate default column names:
ctj sample-no-header.csv -n -p
Given a CSV file sample-no-header.csv without headers:
,,
,,FALSE
,55.5,
Output:
[
{
"column_0": "",
"column_1": "",
"column_2": ""
},
{
"column_0": "",
"column_1": "",
"column_2": false
},
{
"column_0": "",
"column_1": 55.5,
"column_2": ""
}
]
You can pipe CSV data directly into ctj:
# Basic piped input
cat sample.csv | ctj -p
# Processing data from a URL
curl -s https://example.com/data.csv | ctj --pretty
# Process data and save to file
echo "name,score\nAlice,95.5\nBob,87" | ctj > results.json
# Process without headers and pretty print
echo "John,30,Tokyo\nJane,25,Osaka" | ctj --no-header --pretty
Output for the last command:
[
{
"column_0": "John",
"column_1": 30,
"column_2": "Tokyo"
},
{
"column_0": "Jane",
"column_1": 25,
"column_2": "Osaka"
}
]
The tool automatically detects and converts data types:
25, 100) are detected as integers95.5, 87.2) are detected as floatstrue, false, TRUE, FALSE, True, False are converted to JSON booleans (case-insensitive)This project is available under the MIT License.