X Xerobit

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...

Mian Ali Khalid · · 4 min read
Use the tool
CSV to JSON Converter
Convert CSV files to JSON with proper quoting and escaping.
Open CSV to JSON Converter →

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

FeatureCSVTSV
DelimiterComma (,)Tab (\t)
Quoting required forCommas, newlines, quotes in valuesTabs, newlines in values
Common in values?Yes — addresses, namesRarely
Spreadsheet supportExcellentGood (Excel, Google Sheets)
Human readabilityLow (commas blend in)Medium (tabs create visual alignment)
URL/HTML safetyComma is often safeTab 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:

  1. Fields separated by \t (tab, U+0009)
  2. Records terminated by \n or \r\n
  3. Tab characters within field values must be escaped (implementation-dependent)
  4. 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 posts

Related tool

CSV to JSON Converter

Convert CSV files to JSON with proper quoting and escaping.

Written by Mian Ali Khalid. Part of the Data & Format pillar.