// converters
YAML to TSV.
Take a YAML array of maps and export it as tab-separated values.
YAML input
TSV output
YAML to TSV — tab-separated values.
TSV (Tab-Separated Values) works like CSV but uses tabs instead of commas as the delimiter. TSV is preferred when your data contains commas — using CSV would break the column boundaries. Tabs are rarely found in data values, making TSV more robust for messy data.
The conversion logic is identical to YAML-to-CSV: each YAML array element becomes a row, each key becomes a column, and nested objects are flattened. The difference is that tab characters separate values instead of commas, and values containing tabs are quoted.
CSV vs TSV — when to use which.
Use CSV when your data is clean and doesn't contain commas, quotes, or newlines. CSV is more widely supported and more compact (commas take less space than tabs in visual alignment). Use TSV when your data contains commas, when you're pasting into a tool that uses comma as a decimal separator (European locales), or when you need a simpler parsing rule.
Many scientific and data tools (R, pandas, statistical software) default to TSV for these reasons. Google Sheets and Excel can import both formats. When in doubt, try CSV first — switch to TSV if the output looks broken.
Tips for clean conversion.
Ensure your YAML array elements have consistent keys. If the first element has name and email but the second has name, email, and phone, the output will have an empty phone column for the first row. Normalize your data before converting for cleaner output.
TSV format details.
TSV files are plain text where each row is a line of tab-separated values. The format is defined by RFC 4180 for CSV but the same principles apply to TSV with tabs replacing commas. Each field is separated by a single tab character, and rows are separated by newlines. The first row typically contains column headers.
Unlike CSV, TSV rarely requires quoting because tab characters almost never appear in data values. This makes TSV simpler to both generate and parse. When a field does contain a tab, it is typically escaped or the field is enclosed in double quotes following the same rules as CSV.
Excel and spreadsheet integration.
TSV is one of the easiest formats to import into Excel and Google Sheets. In Excel, go to Data → From Text/CSV, select your TSV file, and choose tab as the delimiter. Google Sheets can import TSV directly via File → Import → Upload. Both tools will automatically detect column boundaries from the tab separators.
When pasting TSV data directly into a spreadsheet cell, Excel and Google Sheets will automatically split the data into columns at each tab. This makes TSV ideal for quick data transfers — copy from this tool and paste straight into your spreadsheet without saving a file first.
Common conversion scenarios.
Database exports. Many database tools output TSV by default. Convert the export to YAML for documentation, configuration, or further processing with YAML-aware tools.
Log data. Server logs and monitoring output often use tab-aligned fields. Convert log snippets to YAML for structured analysis and validation.
Data cleaning pipelines. Use TSV as an intermediate format when your source data contains commas. Convert to TSV first, then to YAML for hierarchical organization and comments.
FAQ
How do I convert YAML to a tab-separated file?
`yq -p=yaml -o=tsv '.[]' file.yaml` outputs tab-separated rows; for general tabular output use `yq -o=tsv` or `miller --y2t`.
Can I convert nested YAML to TSV by flattening it first?
Yes — flatten with `yq '... explode(.)'` first, then convert: `yq -o=tsv` will produce proper TSV with dot-notation keys as headers.
How do I preserve YAML list order when converting to TSV?
TSV is ordered by nature (rows are sequential); `yq -o=tsv '.[]'` outputs in document order, so list order is preserved automatically.
How do I output only specific YAML fields as TSV columns?
`yq -p=yaml -o=tsv '.[] | [.name, .age, .city]' file.yaml` picks exactly those fields as columns in the TSV output.
What's the easiest way to get TSV from YAML for pasting into Excel?
`yq -o=tsv '.[]' file.yaml | pbcopy` (macOS) or `| clip` (Windows) — paste directly into Excel/Sheets which auto-detects tab delimiters.