Sometimes, we want to parse XLSX and create JSON with Node.js.
In this article, we’ll look at how to parse XLSX and create JSON with Node.js.
How to parse XLSX and create JSON with Node.js?
To parse XLSX and create JSON with Node.js, we can use the xlsx
package.
To install it, we run
npm i xlsx
Then we use it by writing
const XLSX = require("xlsx");
const workbook = XLSX.readFile("Master.xlsx");
const { SheetNames: sheetNames } = workbook;
console.log(XLSX.utils.sheet_to_json(workbook.Sheets[sheetNames[0]]));
to call XLSX.readFile
to read the XLSX file from the path in the argument/
Then we get the sheetNames
from the workbook
object.
Next, we call XLSX.utils.sheet_to_json
with the first sheet which we get from workbook.Sheets[sheetNames[0]]
return the JSON data converted from the worksheet.
Conclusion
To parse XLSX and create JSON with Node.js, we can use the xlsx
package.