TSV Format Guide — Tab-Separated Values vs CSV
TSV (Tab-Separated Values) avoids the quoting complexity of CSV because tab characters rarely appear in data. Learn the TSV format, when to prefer TSV over CSV, and how to...
TSV (Tab-Separated Values) uses tab characters (\t) as field delimiters instead of commas. Because tabs are rare in natural text, TSV avoids much of the quoting complexity required by CSV.
Convert TSV and CSV to JSON with the CSV to JSON Converter.
TSV vs CSV
| Feature | CSV | TSV |
|---|---|---|
| Delimiter | Comma (,) | Tab (\t) |
| Quoting required for | Commas, newlines, quotes in values | Tabs, newlines in values |
| Common in values? | Yes — addresses, names | Rarely |
| Spreadsheet support | Excellent | Good (Excel, Google Sheets) |
| Human readability | Low (commas blend in) | Medium (tabs create visual alignment) |
| URL/HTML safety | Comma is often safe | Tab is always safe |
Use TSV when: Your data contains commas (addresses, sentences, lists) and you want to avoid quoting complexity.
Use CSV when: You need maximum compatibility with tools and databases.
TSV format rules
name\temail\tage\tcity
Alice Johnson\talice@example.com\t30\tNew York
Bob Smith\tbob@example.com\t25\tLos Angeles
"Tab\there"\tbob@example.com\t25\tLos Angeles
Rules:
- Fields separated by
\t(tab, U+0009) - Records terminated by
\nor\r\n - Tab characters within field values must be escaped (implementation-dependent)
- No universal quoting standard — unlike CSV, TSV doesn’t have RFC 4180
Parse TSV in JavaScript
// Simple TSV parsing (no quoting support needed for typical data):
function parseTSV(text) {
const lines = text.trim().split('\n');
const headers = lines[0].split('\t').map(h => h.trim());
return lines.slice(1)
.filter(line => line.trim() !== '')
.map(line => {
const values = line.split('\t');
return Object.fromEntries(headers.map((h, i) => [h, values[i] ?? '']));
});
}
const tsv = `name\temail\tage
Alice\talice@example.com\t30
Bob\tbob@example.com\t25`;
console.log(parseTSV(tsv));
// [{ name: 'Alice', email: 'alice@example.com', age: '30' }, ...]
// Using PapaParse (handles TSV with delimiter option):
import Papa from 'papaparse';
Papa.parse(tsvText, {
delimiter: '\t',
header: true,
skipEmptyLines: true,
complete: (results) => {
console.log(results.data);
},
});
Parse TSV in Python
import csv
def parse_tsv(file_path: str) -> list[dict]:
"""Parse a TSV file into a list of dicts."""
with open(file_path, newline='', encoding='utf-8') as f:
reader = csv.DictReader(f, delimiter='\t')
return list(reader)
# Or with pandas:
import pandas as pd
df = pd.read_csv('data.tsv', sep='\t')
records = df.to_dict('records')
Convert TSV to JSON
import csv
import json
from pathlib import Path
def tsv_to_json(tsv_path: str, json_path: str, cast_numbers: bool = True):
"""Convert TSV to JSON array of objects."""
with open(tsv_path, newline='', encoding='utf-8') as f:
reader = csv.DictReader(f, delimiter='\t')
records = []
for row in reader:
if cast_numbers:
# Try to cast numeric fields:
casted = {}
for key, value in row.items():
try:
casted[key] = int(value)
except ValueError:
try:
casted[key] = float(value)
except ValueError:
casted[key] = value
records.append(casted)
else:
records.append(dict(row))
Path(json_path).write_text(json.dumps(records, indent=2))
print(f"Converted {len(records)} rows")
return records
TSV from APIs and tools
TSV is common in data export contexts where commas would complicate parsing:
# Tab-separated output in terminal tools:
ps aux | awk '{print $1"\t"$2"\t"$11}' # TSV output
# MySQL: export as TSV
mysql -e "SELECT name, email, age FROM users" --batch > users.tsv
# --batch flag uses tab delimiters automatically
# PostgreSQL COPY to TSV:
\copy users TO 'users.tsv' WITH (FORMAT TEXT, DELIMITER E'\t', HEADER true)
Google Sheets: export as TSV
Google Sheets exports as .tsv via:
- File → Download → Tab-separated values (.tsv)
- Or use the URL:
https://docs.google.com/spreadsheets/d/{ID}/export?format=tsv&gid={GID}
Related tools
- CSV to JSON Converter — convert CSV and TSV to JSON
- JSON Formatter — validate converted JSON
- Regex Tester — test TSV parsing patterns
Related posts
- CSV Quoting and Escaping Rules (the Real Ones, Not the Folklore) — CSV looks trivial until your spreadsheet has a comma in a name field. Here's the…
- CSV Data Validation — Schema Validation, Type Checking, and Error Reporting — Validate CSV files before importing them into a database or processing pipeline.…
- Import CSV to Database — PostgreSQL, MySQL, SQLite, and Node.js — Import CSV files into PostgreSQL, MySQL, and SQLite using COPY commands, LOAD DA…
- CSV Format Guide — Structure, Delimiters, and Common Parsing Issues — CSV (Comma-Separated Values) is a simple tabular text format. Here's the RFC 418…
- Parse CSV in JavaScript — PapaParse, csv-parse, and Manual Parsing — Parse CSV files in JavaScript with PapaParse (browser), csv-parse (Node.js), or …
Related tool
Convert CSV files to JSON with proper quoting and escaping.
Written by Mian Ali Khalid. Part of the Data & Format pillar.