Spreadsheet to JSON CLI (spread-cli)
Converts spreadsheets and CSV/TSV files to JSON, JSON Lines, or plain text -- designed to pipe straight into jq/yq.
Supported formats:
- Excel 2007+ Workbook (.xlsx)
- Excel 2007+ Macro-Enabled Workbook (.xlsm) -- read as plain data; macros are ignored
- Excel 2007+ Binary (.xlsb)
- Excel 97-2004 Legacy (.xls)
- OpenDocument Spreadsheets (.ods) compatible with LibreOffice
- CSV: comma separated values (.csv)
- TSV: tab-separated values (.tsv)
Installation
Installs the spread-cli binary to ~/.cargo/bin, already on your PATH via rustup -- ready to use right away. (This is cargo install, not cargo add -- cargo add only adds a dependency to a Rust project; it won't put a binary on your PATH.)
Quick start
| | |
Four things worth knowing up front:
- Piping into
jq/yq? You almost always want-r(rows as a JSON array) or-l(JSON Lines) -- see Using with jq/yq. - Want one clean JSON object, metadata included? Add
-j/--json. Without it, the default full-result output is plain text (readable lines likerow count: 42) with a JSON array only after thedata:line -- the output as a whole is not valid JSON without-j.-r/-loutput is always valid JSON/JSONL either way;-jthere only changes indentation. - Exploring an unfamiliar, large, multi-sheet workbook? Start with
-x(structural overview -- sheet names, row counts, field names, no cell values) combined with-p(every sheet, not just one);-xpjgives a clean JSON version. Then target the sheet(s)/field(s) you actually want with-s/--keys/-r/-l. - Sheet and row numbers are 1-based by default (
-n,-t,-b), matching what you'd see in a spreadsheet app. 0-based equivalents exist for scripts that already track things by index -- see Options.
Spreadsheet notes
Field names come from the header row, snake_cased (e.g. "Gross Annual Salary (USD)" becomes gross_annual_salary_usd). If the header isn't on the first row, spread-cli detects it automatically -- title/notes rows above it, and a gap before the real data starts, are recognized and skipped. Override with -t/-b if it guesses wrong, or --omit-header if there's no header row at all.
For wide spreadsheets with long or awkward header text, it's often easier to force every column to a short fallback key, then reassign the ones you care about with --keys, rather than typing out each header name in full -- -A/--a1 for letters (a, b, ...) or -R/--r1c1 for zero-padded numbers (c01, c02, ...):
Column mapping patterns (--keys)
Beyond simple renames (--keys "old:new"), --keys understands three placeholder
patterns for merging a run of similarly-named columns into one nested field --
handy for spreadsheets that spread one logical field across several columns
(file_1, file_2, file_3, ... or sales_north, sales_south, ...).
The source side captures whatever text follows a literal prefix: [name] captures it as
a number, {name} as text. The capture name only matters if it's referenced again on the
target side. (Why brackets/braces work this way: see 0.2.0 in Version History.)
Plain array -- merge sequential columns into one array of scalars, in column order:
file_1=a.pdf, file_2=b.pdf, file_3= (blank) becomes:
Blank cells are dropped, and an all-blank row still yields files: [], never an absent
key. Two shorthands for the common case where the capture name is never reused:
file_*:files[] (glob-style) and file_[]:files[] (empty brackets) both mean the same
as file_[n]:files[].
Dynamic-keyed object -- turn each matching column into its own key inside a shared nested object, using the captured text as the key:
sales_north=120, sales_south=95 becomes:
Array of objects -- turn each matching column into its own item in an array of objects, with the captured value as one field and the cell's own value as another:
sales_2024=100, sales_2025=150 becomes:
Swap {amount} for whatever field name you want (e.g. {year}{value}) -- the field
after the capture always holds the cell's own value, and takes its JSON type (number vs
text) from whichever bracket style the source pattern used for that capture.
All three forms mix freely with ordinary renames in the same comma-separated --keys
value, and work against xlsx/xlsm/xls/xlsb/ods just as well as CSV/TSV. They cover the
common cases by design -- anything more elaborate is better done by piping into
jq/yq, or with the spreadsheet-to-json library crate directly, which exposes the
full KeySegment tree these patterns compile down to.
Suppressing columns
Prefix a --keys entry with - to drop that column from the output entirely:
The identifier after the - is matched case-insensitively against:
- the column's natural snake_cased header key by default (
-colour) - its A1 letter in
-A/--a1mode (-dfor column D) - its column number in
-R/--r1c1mode (-4for column 4 ---c4/-c04also work)
An identifier that doesn't match any column is silently ignored, same as an unmatched
ordinary --keys override. Suppressions mix freely with everything else --keys
supports, comma-separated:
Splitting one column into an array
The placeholder patterns above merge several columns into one nested field. For a
single column whose own cell text is already delimited ("a.pdf|b.pdf",
"north,south,east"), use the array format instead -- type[] or type[](separator)
as the |format part of an ordinary --keys entry:
type is any of the usual format codes (text, int, float, ...), applied to each
element after splitting -- it must be one of those real codes, not the column/field
name (an unrecognized word here is silently treated the same as text, rather than
erroring, so a typo casting to int[] won't be caught). If you'd rather write it in a
more familiar, JS-like form, .split(...) works identically -- only the text between
] and ( is ignored (that's where the function name goes), and a matching pair of
quotes around the separator is stripped if present:
All three forms above are equivalent. This is a single-column cast (Format::Array in
the underlying library), not a placeholder pattern -- no [name]/{name} capture is
involved, and it can be freely mixed with renames, other overrides, and placeholder
patterns in the same comma-separated --keys value.
Options
-
pathLocal path to the source spreadsheet or CSV/TSV file -
-s, --sheetcase-insensitive sheet name, ignoring spaces/punctuation; falls back to the first sheet if unmatched -
-n, --numbersheet number, 1-based (-n 1is the first sheet) -
-k, --keys: comma-separated column overrides,source_key[:new_key][|format[|default]].source_keymatches the column's natural (auto-detected, snake_cased) header name wherever it actually is, so you only list the columns you want to change -- an unmatchedsource_keyis silently ignored. Omit:new_keyto change only the format/default:--keys "start_date|date"castsstart_dateto a date, keeping its name--keys "start_date:start|date"also renames it tostart--keys "start_date:start|date,total_price:total"mixes several overrides in one valuedateis one of several date/time format codes -- see the table under--date-onlybelow--keys "-colour"(leading-) suppresses that column instead -- see Suppressing columns--keys "file_[n]:files[]"and two other placeholder patterns merge several columns into nested output -- see Column mapping patterns--keys "tags|text[](,)"splits one column's delimited text into a JSON array instead -- see Splitting one column into an array
-
-X, --exclude-nulldrops any key whose value is JSONnullfrom output, recursively through nested objects/arrays too, instead of emitting"key": null. Only ever targets genuinenull-- an empty string is a different, deliberate value and is left alone. -
-m, --maxmax rows per sheet (with-p, every sheet gets its own cap, default 10) -
-t, --topheader row number, 1-based, if the header isn't on the first row -- e.g. a title/notes row above it. If not given, the header row is detected automatically. -
-b, --body-startrow number, 1-based, where the real data begins, if there's a gap below the header (a blank or subtitle row). Rows between the header and this one are skipped entirely. Defaults to immediately after the header row.- Example: title in row 1, notes in row 2, real header in row 3, blank row before data in row 5 --
-t 3 -b 5skips straight past the blank row instead of capturing it as a row of nulls. - With
-j, the row indices actually used -- whether from-t/-bor auto-detection -- come back asheader_row/body_start(1-based) andheader_index/body_index(0-based).
- Example: title in row 1, notes in row 2, real header in row 3, blank row before data in row 5 --
-
--omit-headertreat the file as having no header row at all; columns get fallback letter names (a,b,c, ... orc01,c02, ... with--colstyle) instead. Pair with--keysto give them real names:--omit-header --keys "a:region,b:team_size,c:revenue". -
-c, --colstyle: fallback column-naming style for columns with no usable header,style[:mode]--styleisa1(letters) orc01/r1/r1c1(zero-padded numbers);modeisall(every column, the default) or anything else to only fill in columns lacking a real header. -
-A, --a1(alias-a) shorthand for-c a1-- every column named by its A1 letter instead of its header. Ignored if--colstyle/-cis also given explicitly. -
-R, --r1c1shorthand for-c c01-- every column named by its zero-padded number (c01,c02, ...) instead of its header. Ignored if--colstyle/-cis also given explicitly. -
-d, --deferredFor large files: streams rows to a.jsonlfile instead of holding them all in memory. Defaults to a random-UUID filename underEXPORT_FILE_DIRECTORY(a.envvariable, default./) -- name it yourself with-o. On Linux/macOS this runs as a detached background process and returns immediately; check{path}.logafterward to confirm it finished. On Windows it runs in-process instead, still memory-efficient, just blocking. -
-o, --outputexport file path for-d; has no effect without it -
-j, --jsonoutputs one valid, indented JSON object/array for the full result -- see Quick start above for why this matters -
-p, --previewreads every worksheet (up to-mrows each, default 10) instead of just one ---s/-nare ignored in this mode. Field names for every sheet come back in a top-levelcolumnsmap; each sheet's rows live underdata. -
-x, --overviewdrops row values, keeping only structure -- sheet names, row counts, field names. Combine with-p(-xp) for a full-workbook overview with no cell data at all:columns(fields per sheet) androw_counts(rows per sheet), nodatakey. See Quick start. (Also accepted as--exclude-cells, its original name.) -
-r, --rowsjust the data rows, as a JSON array, no metadata wrapper -
-l, --linesJSON Lines: one compact object per row, no wrapper -- implies-r -
--euro-number-format: parse decimal commas when converting formatted strings to numbers -
--date-only/--time-only/--hm-only/--simpleformat every date-time column as a date, a time, hours:minutes, or a full date-time without milliseconds/Z, respectively. Each wins over the ones after it if more than one is set (--date-only>--time-only>--hm-only>--simple).To override just one column instead, use
--keys "col|<code>":code example output notes dt/datetime(or no override)2026-07-19T19:58:45.000Zthe default: full precision, JS/JSON-interop-friendly ds/simple2026-07-19T19:58:45full date-time, no milliseconds or Zda/date2026-07-19date only ti/time19:58:45time only, with seconds hm19:58time only, hours and minutes e.g.
--keys "logged_at|hm"renders justlogged_atas"19:58", leaving every other date-time column at its row-wide default.time/hmalso recover a time from a plain decimal number or dot-separated string (12.3->12:30) and a trailing AM/PM marker ("2:30pm"->14:30) -- only ever under an explicit|time/|hmoverride, never automatically. Hours are not capped at 24, since a "time" column is just as often a duration as a time-of-day. (Full mechanics and edge cases: seespreadsheet-to-json's Version History,0.3.0and0.3.2.)Other date/time transformations (reformatting, day-of-week, timezone conversion) are out of scope here -- pipe into
jq/yq, or use thespreadsheet-to-jsonlibrary crate directly for Rust code. -
--debugprints processing time and extra diagnostic detail on error, to stderr when the main output is JSON (so it never corrupts a piped result)
0-based equivalents, for scripts that already track rows/sheets by index rather than the friendly 1-based numbers above: --index (= -n), --header-index (= -t), --body-index (= -b).
Using with jq (or yq)
For piping, reach for -r (rows as a JSON array) or -l (JSON Lines) -- both are always valid JSON/JSONL on their own, with or without -j. yq handles either shape just as well as jq -- including line-delimited JSON, which it reads as a stream of separate documents:
|
-j/--json only matters for the full result (no -r/-l) -- see Quick start -- and it's a pure formatting flag there too: indentation, not content.
# full result: metadata (extension, sheets, row_count, fields, ...) + data together
|
|
# -p: every worksheet, not just the selected one -- field names per sheet in "columns",
# rows come back per-sheet under "data"
| |
# -xpj: a quick structural overview of every worksheet, no row data at all -- just sheet
# names, field names ("columns"), and row counts ("row_counts"). Ideal for large
# multi-sheet files (e.g. statistics-agency spreadsheets) before deciding what to pull.
|
|
# -rj (or -r --json): just the rows, as a pretty-printed array, no metadata wrapper
|
|
|
# -l: plain JSON Lines, one row per line -- best for streaming into another
# NDJSON-consuming tool, or very large files (jq/yq consume it line-by-line rather than
# waiting for one big array to finish printing)
|
|
|
Version History
Pre-0.2.0 releases aren't individually catalogued here; see the git history.
- 0.2.0 Added the three
--keysplaceholder-pattern DSLs and column suppression -- see Column mapping patterns above.[name]/{name}in the source pattern deliberately mirror JSON's own shape as a mnemonic: square brackets (arrays are index-ordered) type the capture as a number, curly braces (objects are string-keyed) as text. Added-A/--a1(alias-a) and-R/--r1c1as shorthands for--colstyle a1/c01; both take the capital consistently ---Rsince-ralready means--rows, and-Ato match it -- and-Ris often the more practical choice for very wide sheets once A1 letters run pastzinto double letters. Added-X/--exclude-null, wiring the library'sRowOptionSet::omit_null_valuesthrough to the CLI.