TSV to JSONTSV
Tab-separated values.
Delimited format using tabs. Common for spreadsheet data copied to the clipboard, database exports, and bioinformatics data.
A TSV file separates columns with a tab character and rows with a line break. Tabs rarely occur inside values, so TSV is a common export format for databases and scientific tools. It is also the format Excel and Google Sheets put on the clipboard when you copy a range of cells.
TabularJS reads .tsv and .tab files with the same parser as CSV, fixed to the tab delimiter, and returns the rows as strings in a worksheets array.
Feature support
What TabularJS extracts from TSV files
- One worksheet.
dataholds every row, including the header row, as arrays of strings, padded to the same length. - Double-quoted fields are handled as in CSV, so a value can contain a tab or a line break when it is quoted.
columnswith the titles A, B, C...- Text that looks like a formula, such as
=A1*2, is kept as that text.
Convert TSV to JSON in Node.js
import tabularjs from 'tabularjs';
const result = await tabularjs('scores.tsv');
console.log(result.worksheets[0].data);
// [ [ 'id', 'name', 'score' ],
// [ '1', 'Alice', '90' ],
// [ '2', 'Bob, Jr.', '85' ] ]Read TSV files in the browser
import tabularjs from 'tabularjs';
// Paste a range copied from Excel or Google Sheets
document.addEventListener('paste', async (event) => {
const text = event.clipboardData.getData('text/plain');
const bytes = new TextEncoder().encode(text);
const result = await tabularjs(bytes, { extension: 'tsv' });
console.log(result.worksheets[0].data);
});JSON output
{
"worksheets": [
{
"data": [
["id", "name", "score"],
["1", "Alice", "90"],
["2", "Bob, Jr.", "85"]
],
"columns": [{ "title": "A" }, { "title": "B" }, { "title": "C" }]
}
]
}Complete output for a three-line TSV file. Numbers stay strings, exactly as written.
Options
| Option | Effect for TSV |
|---|---|
| encoding | Text encoding. Default utf-8; any TextDecoder label, plus iconv-lite codepages in Node.js. |
| extension | Set 'tsv' for clipboard text or bytes without a file name. |
| delimiter | Ignored for .tsv and .tab: they always use tabs. For another separator use a .txt or .csv file with delimiter. |
Limitations
- No type conversion: numbers and dates stay strings.
- The whole file is read into memory; there is no streaming mode.
Frequently asked questions
How do I parse spreadsheet data pasted from the clipboard?
Read the text with event.clipboardData.getData('text/plain'), encode it with new TextEncoder().encode(text) and call tabularjs(bytes, { extension: 'tsv' }). Excel and Google Sheets copy ranges as tab-separated text.
What is the difference between .tsv, .tab and .txt in TabularJS?
.tsv and .tab always use a tab delimiter. .txt uses a tab by default but accepts the delimiter option, so use .txt rules for pipe or semicolon files.
Are TSV values converted to numbers?
No. Every value is returned as a string. Convert the columns you need with Number().
What if the file has no extension?
TabularJS looks at the content: if the first line contains a tab and no comma, it is parsed as TSV, otherwise as CSV. Pass { extension: 'tsv' } to skip the detection.
Can a TSV value contain a tab or a line break?
Yes, if the value is enclosed in double quotes. The quotes are removed and the tab or line break is kept in the value.
Why TabularJS for TSV?
- No external spreadsheet parser dependencies: faster installs, smaller bundles.
- One API in Node.js and modern browsers.
- Output is shape-compatible withJspreadsheet: render parsed data in a live workbook with one call.