Convert Excel to JSON in JavaScript
SheetJS reads .xlsx, .xls, .ods and .csv files in plain JavaScript, and one function turns a sheet into an array of objects. This is the code behind the Excel to JSON converter on this site, with the options that matter.
Install SheetJS
SheetJS publishes current versions on its own CDN. The xlsx package on the npm registry stopped at
0.18.5, so install the tarball:
npm i https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz
In the browser
Read the file from an <input type="file"> as an ArrayBuffer and parse it:
import * as XLSX from 'xlsx';
input.addEventListener('change', async () => {
const file = input.files[0];
const workbook = XLSX.read(await file.arrayBuffer(), { cellDates: true });
const sheet = workbook.Sheets[workbook.SheetNames[0]];
const rows = XLSX.utils.sheet_to_json(sheet, { UTC: true });
console.log(rows);
});
Nothing leaves the browser. workbook.SheetNames lists every sheet in order, so you can offer a
picker the way the Excel to JSON converter does.
In Node.js
The ES module build does not load fs on its own. Hand it over with set_fs before
calling readFile, or read the bytes yourself and use read:
import * as XLSX from 'xlsx';
import fs from 'fs';
XLSX.set_fs(fs);
const workbook = XLSX.readFile('people.xlsx', { cellDates: true });
const rows = XLSX.utils.sheet_to_json(workbook.Sheets.People, { UTC: true });
fs.writeFileSync('people.json', JSON.stringify(rows, null, 2));
What sheet_to_json returns
For a sheet with the header row name | id | city | joined and two rows, where Grace has no join date:
[
{ "name": "Ada", "id": 1, "city": "London", "joined": "2026-01-15T00:00:00.000Z" },
{ "name": "Grace", "id": 2, "city": "New York" }
]
- The first row gives the keys. Numbers and booleans keep their type.
- Empty cells are left out, so Grace's object has no
joinedkey. - Repeated headers get a suffix: two columns named
namebecomenameandname_1.
Options worth knowing
{ defval: null }writes empty cells asnull, so every object has every key.{ header: 1 }returns arrays instead of objects, header row included, which is handy for tables without a header.{ header: 'A' }uses the column letters as keys.{ raw: false }returns the text Excel displays, so1becomes"1"and a date becomes"1/15/26".{ range: 1 }skips the first row and uses the second row as the header.
Dates
Excel stores dates as serial numbers. Without options you get 46037 instead of 15 January 2026.
cellDates: true in read turns them into Date objects. Add
UTC: true to sheet_to_json as well: without it, a date read in a time zone east of
UTC came out as 2026-01-14T21:00:00.000Z in my test, one day early once you drop the time.
Going the other way, from JSON to a sheet, is covered in JSON to Excel in JavaScript.