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
What TabularJS extracts from CSV files
- One worksheet.
dataholds every row, including the header row, as arrays of strings. Short rows are padded with empty strings so every row has the same length. - Quoted fields:
"Paris, FR"keeps its comma,"said ""hi"""becomessaid "hi", and a quoted field can contain line breaks. columnswith the titles A, B, C... The header row is not used for column titles.- Text that looks like a formula, such as
=SUM(A1:A2), is kept as that text. It is not evaluated or removed, so escape it before you show user-supplied CSV in a spreadsheet that calculates formulas.
Convert CSV to JSON in Node.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
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
{
"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
| Option | Effect for CSV |
|---|---|
| delimiter | Column separator, one character. Default ,. Use ';' for files from Excel in locales that use a decimal comma. |
| encoding | Text 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. |
| extension | Set 'csv' when the input has no file name, for example a Uint8Array. |
Limitations
- The delimiter is not detected. A semicolon or pipe separated file needs the
delimiteroption. - No type conversion: numbers, booleans and dates stay strings. Convert the columns you need with
Number()or your own parser. - The whole file is read into memory; there is no streaming mode for very large files.
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?
- 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.