All formats

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

Data values
Formulas
Styles
Merged cells
Comments
Column metadata

What TabularJS extracts from TSV files

Convert TSV to JSON in Node.js

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

js
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

json
{
  "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

OptionEffect for TSV
encodingText encoding. Default utf-8; any TextDecoder label, plus iconv-lite codepages in Node.js.
extensionSet 'tsv' for clipboard text or bytes without a file name.
delimiterIgnored for .tsv and .tab: they always use tabs. For another separator use a .txt or .csv file with delimiter.

Limitations

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?