CSV — Practical Examples
Output: Generate CSV from a list
From a list of dicts (header auto-derived from keys)
The CSV header is taken from the dict keys. Column order follows insertion order.
echo '[{"name":"Alice","age":30},{"name":"Bob","age":25}]' | \
fimod s -e 'data' --output-format csv
Controlling the header (column names and order)
Return dicts with the exact keys you want. The key names become column headers.
fimod s -i https://jsonplaceholder.typicode.com/users \
-e '[{"id": u["id"], "name": u["name"], "email": u["email"], "city": dp_get(u, "address.city")} for u in data]' \
-o contacts.csv
Without header row (--csv-no-output-header)
Useful for appending to an existing file or feeding into tools that expect raw rows.
echo '[{"name":"Alice","age":30},{"name":"Bob","age":25}]' | \
fimod s -e 'data' --output-format csv --csv-no-output-header
Input: CSV with header
Default behavior — the first row is treated as the header. Each row becomes a dict keyed by column name.
Casting values
All values come in as strings. Cast explicitly when needed:
printf 'name,age\nAlice,30\nBob,25\n' | \
fimod s -e '[{**row, "age": int(row["age"])} for row in data]' \
--input-format csv --output-format json
Input: CSV without header
Using --csv-header to name the columns
When the file has no header row, use --csv-header to declare column names.
Rows arrive as dicts with those names.
printf 'Alice,30\nBob,25\n' | \
fimod s -e 'data' --input-format csv --csv-header "name,age" --output-format json
Using --csv-no-input-header (columns as lists)
When no header is declared, rows arrive as plain lists (["Alice", "30"]).
Access columns by index.
printf 'Alice,30\nBob,25\n' | \
fimod s -e '[{"name": r[0], "age": int(r[1])} for r in data]' \
--input-format csv --csv-no-input-header --output-format json
Custom delimiter (TSV and others)
Tab-separated input
printf 'name\tage\nAlice\t30\nBob\t25\n' | \
fimod s --input-format csv --csv-delimiter '\t' -e 'data' --output-format json
Semicolon-separated input (common in European locales)
printf 'name;age\nAlice;30\nBob;25\n' | \
fimod s --input-format csv --csv-delimiter ';' -e 'data' --output-format json