TSV: Tab-Separated Values and When to Use Them Over CSV
TSV vs CSV, converting between TSV and JSON, and why tabs sometimes make a cleaner delimiter than commas.
What Is TSV?
Tab-Separated Values (TSV) is a plain-text format where each row is a line and fields within a row are separated by tab characters (\t, Unicode U+0009). Like CSV, TSV has no official standard — implementations vary — but the basic structure is universally understood.
TSV example
name age city
Alice 30 London
Bob 25 ParisTSV vs CSV: When Does Each Win?
TSV advantages
- No quoting needed for commas: Data containing commas (addresses, phrases) doesn't need escaping — tabs rarely appear in regular text data
- Copy-paste from spreadsheets: When you select cells in Excel or Google Sheets and copy, the clipboard format is tab-separated. Pasting into a TSV tool "just works"
- Simpler parsing: You can split on
\twithout worrying about quoted fields containing the delimiter
CSV advantages
- Universal support: More tools, databases, and import wizards accept
.csvfiles by default - RFC standard: RFC 4180 defines CSV quoting rules — TSV has no equivalent standard
- Human readability: For data without commas, CSV is slightly easier to read in a text editor
Parsing TSV to JSON
Because tabs don't appear in typical data, TSV is simpler to parse than CSV — you usually don't need to handle quoted fields:
function tsvToJson(tsv) {
const lines = tsv.trim().split('\n');
const headers = lines[0].split('\t');
return lines.slice(1).map(line => {
const values = line.split('\t');
return Object.fromEntries(
headers.map((h, i) => [h.trim(), values[i]?.trim() ?? ''])
);
});
}Converting JSON to TSV
function jsonToTsv(records) {
if (!records.length) return '';
const keys = Object.keys(records[0]);
const header = keys.join('\t');
const rows = records.map(r =>
keys.map(k => String(r[k] ?? '').replace(/\t/g, ' ')).join('\t')
);
return [header, ...rows].join('\n');
}Note the tab sanitization: any tab characters within field values are replaced with spaces to prevent broken output. For CSV, you'd quote the field instead — TSV has no standardized quoting.
The Spreadsheet Copy-Paste Workflow
One of the most common TSV workflows is quick data export from a spreadsheet:
- Select cells in Excel or Google Sheets
- Copy (Ctrl+C / Cmd+C)
- Paste into a TSV-to-JSON converter
- Use the JSON output in your code or API request
This is faster than exporting a .csv file, especially for ad-hoc data transformation tasks. The reverse — converting a JSON API response to TSV and pasting into a spreadsheet — is equally common for data analysis.
Common Pitfalls
- Hidden carriage returns: Windows line endings (
\r\n) can leave\rat the end of the last field per row — trim values when parsing - Tabs in data: If your data actually contains tabs (rare but possible), TSV breaks without quoting — fall back to CSV or escape tabs as
\\t - Inconsistent column counts: Missing trailing tabs can make some rows shorter than others — handle sparse data explicitly
- BOM characters: Excel sometimes prepends a UTF-8 BOM (
) to copied data — strip it before parsing
Try it yourself
Paste TSV directly from a spreadsheet and convert it to JSON instantly — or convert JSON back to TSV.
Open TSV to JSON →