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:
Skipping ranges and nested paths (--skip-cols)
For dropping more than a column or two at once, -K/--skip-cols takes a
comma-separated list with three forms, none needing the leading - (everything here is
already a suppression):
The a.b.c form targets output that only exists once a --keys pattern has actually
nested something -- on its own, against a plain flat CSV, it's a no-op (there's nothing
at that path to remove yet):
# without -K: {"n": 1, "line1": "1 Road", "admin2": "Countyshire"} per address
# with -K "addresses.$.admin2": the same, minus "admin2", in every item
start..end-- a range by position in the sheet's natural left-to-right column order (same natural-key/A1-letter/R1C1-number identifiers as plain suppression). A range given backwards (the end column actually comes before the start column in the sheet), or an endpoint that doesn't match any column, is a clear error -- not a silent guess at which way you meant it.name,name2-- independent single-column suppressions, equivalent to--keys "-name,-name2"without the-prefix per entry.a.b.c-- a dot-separated output path, removed from the row's final shape (after any--keysnesting) rather than resolved against a source column at all -- this is the only form that can reach inside a--keys-built nested object or array.$as a path segment means "every item of this array" rather than a literal key (addresses.$.admin2dropsadmin2from each address, not the whole array). An unmatched or malformed nested path is silently ignored, same as an unmatched plain column name.
All three forms can be mixed in one comma-separated -K value.
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.
Filtering rows (--filter)
Drop rows that don't match a SQL-like boolean expression, evaluated against each row's
final keys -- after any --keys renames, not raw source columns:
-
Comparisons:
=,!=/<>,>,>=,<,<=, andLIKE/ILIKE(ILIKEis case-insensitive;LIKEisn't) with SQL%wildcards --'a%'(starts with),'%os'(ends with),'%foo%'(contains), or no%at all (exact match). A%in the middle of a pattern ('a%b') isn't supported and is a clear parse error, not a silently wrong match -- that needs two independent anchors, which no single check can express in one pass; split it into twoAND-ed conditions instead. -
IN (...)/NOT IN (...)-- the field's own value equals (or doesn't equal) one of a comma-separated list.ANY (...)/NOT ANY (...)is the array counterpart -- the field's own value must itself be an array (e.g. from--keys "tags|text[]") sharing at least one element with the list; a plain scalar field never satisfiesANY, that's whatINis for. Quotes around a list/comparison value are only required to group a value containing a space or comma into one token --IN (us, gb, ca)andIN ('us', 'gb', 'ca')are equivalent, and a bare value can't reuse a reserved word (and,in,like, ...) as a literal, same as an unquoted identifier in SQL. -
A field reference can be a dot-path into an object
--keyshas already nested (size.width, once--keys "size_{x}:size.{x}"has mappedsize_width/size_heightcolumns into onesizeobject), not just a top-level key. It can't reach inside an array of nested objects, though (addresses.admin2whereaddressesis itself an array) -- matching through an array raises a real "does the row match if any item satisfies it, or only if all do" question that's deliberately left open rather than decided silently. -
Combine with
AND/OR(case-insensitive) --ANDbinds tighter thanOR, override with parentheses -- and negate withNOT(NOT (age >= 18), orfirst_name NOT ILIKE 'a%'). -
A row missing the field entirely does not match (a filter never treats an absent column as satisfying the condition). Filtering always runs before
-X/--exclude-null, so a field-Xwould otherwise strip is still present with its real value when a filter checks it. -
-m/--maxstill bounds how many rows are read, not how many pass the filter -- a heavily-filtered file can return fewer than-mrows even when more matches exist further down, since--maxis a scan cap for quick structural preview of large files, not a "collect N matching rows" limit. To cap the number of matching rows instead, use-L/--limit:Scanning stops as soon as
--limitrows have matched, rather than reading the whole file first -- the two flags compose when both are set, whichever bound is hit first wins (e.g.-m 100 --limit 20stops at 20 matches, or after 100 rows scanned, whichever comes first).
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- three words in square brackets go where the default goes, to say what happens where the column is empty in place of filling it:
--keys "max_height|d6|[skip]"leavesmax_heightout of any row where the cell is not a number, and--keys "code|text|[skip]"leavescodeout where it is blank. What counts as empty follows the format: a number or true/false column is empty unless the cell reads as one (blank andn/aalike), any other column when it is null or an empty string--keys "status|truthy|[omit]"leaves the column out only where it is null after conversion; an empty string stays--keys "code|text|[keep]"writes the column even where-Xwould drop it. A column cast totextis always a string,""when the cell is empty, sorow.code.lengthis safe to read
--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
-
-f, --filterdrops rows that don't match a SQL-like boolean expression against the row's final keys, e.g."age >= 18 and name ILIKE 'a%'"-- see Filtering rows -
-K, --skip-colsdrops a range ("width..depth"), list ("width,depth"), or nested output path ("addresses.$.admin2") of columns from output -- see Skipping ranges and nested paths -
-X, --exclude-nulldrops any key whose cell was empty from output, recursively through nested objects/arrays too, instead of emitting"key": nullor"key": "". Empty means JSONnull(nothing there, or nothing readable as the column's format) or an empty string, which is what an empty text cell reads as. A string of spaces,0andfalseare values and are kept. A column given a default in--keys, or marked[keep]there, is always written. -
-m, --maxmax rows scanned per sheet (with-p, every sheet gets its own cap, default 10) -- keeps scanning up to this many rows regardless of how many pass--filter; suits pagination/batch processing. See Filtering rows for how this differs from-L/--limit. -
-L, --limitmax matching rows returned -- distinct from-m/--maxabove; scanning stops as soon as this many rows have matched (or, with no--filter, simply been read). See Filtering rows. -
-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.