All formats

CSV to JSONCSV

Comma-separated values.

The universal data exchange format. TabularJS handles quoted fields, escaped quotes, line breaks inside quotes, and CRLF or LF line endings.

CSV has no types and many dialects: comma or semicolon separators, quoted fields, Windows or Unix line endings, UTF-8 or a legacy codepage. TabularJS reads the file, splits it with standard double-quote quoting and returns the rows in the same worksheets structure it uses for Excel files, so one code path can handle CSV and XLSX uploads.

It does not guess types or headers. Every value is a string and the first row stays in data as row 0. That keeps the output lossless: 007 stays 007, and 1/2 is not turned into a date.

Feature support

Data values
Formulas
Styles
Merged cells
Comments
Column metadata

What TabularJS extracts from CSV files

Convert CSV to JSON in Node.js

js
import tabularjs from 'tabularjs';

const result = await tabularjs('people.csv');
const [header, ...rows] = result.worksheets[0].data;

console.log(header); // [ 'name', 'city', 'note' ]
console.log(rows[0]); // [ 'Alice', 'Paris, FR', 'said "hi"' ]

// Semicolon-separated file in Windows-1252, as exported by Excel in many European locales
const eu = await tabularjs('prices.csv', { delimiter: ';', encoding: 'windows-1252' });
console.log(eu.worksheets[0].data[1]); // [ 'Café', '3,50' ]

Read CSV files in the browser

js
import tabularjs from 'tabularjs';

document.querySelector('input[type=file]').addEventListener('change', async (event) => {
  const result = await tabularjs(event.target.files[0]);
  const [header, ...rows] = result.worksheets[0].data;

  // Array of objects keyed by the header row
  const records = rows.map((row) => Object.fromEntries(header.map((key, i) => [key, row[i]])));
  console.log(records); // [ { name: 'Alice', city: 'Paris, FR', note: 'said "hi"' }, ... ]
});

JSON output

json
{
  "worksheets": [
    {
      "data": [
        ["name", "city", "note"],
        ["Alice", "Paris, FR", "said \"hi\""],
        ["Bob", "Berlin", "line1\nline2"],
        ["Total", "", "=SUM(A1:A2)"]
      ],
      "columns": [{ "title": "A" }, { "title": "B" }, { "title": "C" }]
    }
  ]
}

This is the complete output for a four-line CSV file. A CSV worksheet has no worksheetName, styles or formulas: just data and columns.

Options

OptionEffect for CSV
delimiterColumn separator, one character. Default ,. Use ';' for files from Excel in locales that use a decimal comma.
encodingText encoding. Default utf-8. Any TextDecoder label works (windows-1252, iso-8859-2, shift_jis...). In Node.js, DOS codepages such as cp850 also work through iconv-lite.
extensionSet 'csv' when the input has no file name, for example a Uint8Array.

Limitations

Frequently asked questions

How do I convert CSV to an array of JSON objects?

Take the first row as keys: const [header, ...rows] = result.worksheets[0].data; then rows.map(r => Object.fromEntries(header.map((h, i) => [h, r[i]]))). TabularJS keeps the header in data so you decide how to use it.

How do I parse a semicolon-separated CSV file?

Pass the delimiter: await tabularjs('file.csv', { delimiter: ';' }). Excel writes semicolons in locales where the comma is the decimal separator.

Why do accented characters show up as question marks?

The file is not UTF-8. CSV files saved by Excel on Windows are often Windows-1252, so use { encoding: 'windows-1252' }, or the codepage the file was written in.

Can I parse a CSV string instead of a file?

Yes, but pass it as bytes. A plain string is treated as a file path (only strings that start with < are treated as HTML), so use await tabularjs(new TextEncoder().encode(csvText), { extension: 'csv' }).

Does TabularJS convert numbers in CSV files?

No. Every CSV value is returned as a string, exactly as it appears in the file, so leading zeros, long IDs and number formats are not changed.

Why TabularJS for CSV?