How to Convert Excel to JSON in JavaScript ? Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Converting Excel spreadsheets to JSON format is a common requirement in various applications. JavaScript code utilizes the read-excel-file library to parse the Excel data, convert it to JSON format, and display it. Additionally, it provides functionality to download the generated JSON file. ApproachCreate an HTML file with a div containing an input file element to allow users to select an Excel file. Also, include a text area to display the JSON data and a button to trigger the conversion process.Reference the "read-excel-file" library in your HTML file. You can find the link to the library in the code.Write JavaScript functions to handle the conversion process. Use event listeners to detect changes in the input file selection. Use the library to read the Excel file and convert it into a JSON string. Display the JSON string in the text area.Implement a function to download the JSON data as a file when the user clicks the download button.Example: The below example shows converting Excel to JSON in JavaScript. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Excel to JSON Converter</title> <style> body { font-family: Arial, sans-serif; margin: 0; padding: 0; } .container { max-width: 800px; margin: 50px auto; padding: 20px; border: 1px solid #ccc; border-radius: 5px; background-color: #f9f9f9; } .input-container { margin-bottom: 20px; } .input-container input[type="file"] { display: none; } .input-container label { display: block; padding: 10px 15px; background-color: #007bff; color: #fff; text-align: center; cursor: pointer; border-radius: 5px; } .input-container label:hover { background-color: #0056b3; } .btn { padding: 10px 15px; background-color: #007bff; color: #fff; border: none; border-radius: 5px; cursor: pointer; } .btn:hover { background-color: #0056b3; } </style> </head> <body> <div class="container"> <div class="input-container"> <input type="file" id="excel_file" accept=".xlsx, .xls" /> <label for="excel_file"> Select Excel File </label> </div> <button class="btn" id="convert_btn"> Convert to JSON </button> <div class="input-container"> <textarea id="json_data" rows="10" cols="50" readonly> </textarea> </div> <button class="btn" id="download_btn"> Download JSON File </button> </div> <script src= "https://unpkg.com/[email protected]/bundle/read-excel-file.min.js"> </script> <script> document .getElementById("convert_btn") .addEventListener("click", function () { const input = document.getElementById("excel_file"); readXlsxFile(input.files[0]).then(function (data) { const headers = data[0]; const jsonData = []; for (let i = 1; i < data.length; i++) { const temp = {}; for (let j = 0; j < headers.length; j++) { temp[headers[j]] = data[i][j]; } jsonData.push(temp); } document.getElementById("json_data") .value = JSON.stringify( jsonData, null, 2 ); }); }); document .getElementById("download_btn") .addEventListener("click", function () { const jsonData = document.getElementById("json_data").value; downloadObjectAsJson(jsonData, "excel_to_json"); }); function downloadObjectAsJson(jsonData, filename) { const dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(jsonData); const downloadAnchorNode = document.createElement("a"); downloadAnchorNode.setAttribute("href", dataStr); downloadAnchorNode.setAttribute("download", filename + ".json"); document.body.appendChild(downloadAnchorNode); downloadAnchorNode.click(); downloadAnchorNode.remove(); } </script> </body> </html> Output: Comment L lunatic1 Follow Improve L lunatic1 Follow Improve Article Tags : HTML JSON Explore HTML BasicsHTML Introduction5 min readHTML Editors5 min readHTML Basics7 min readStructure & ElementsHTML Elements5 min readHTML Attributes8 min readHTML Headings4 min readHTML Paragraphs5 min readHTML Text Formatting4 min readHTML Block and Inline Elements3 min readHTML Charsets4 min readListsHTML Lists5 min readHTML Ordered Lists5 min readHTML Unordered Lists4 min readHTML Description Lists3 min readVisuals & MediaHTML Colors11 min readHTML Links Hyperlinks3 min readHTML Images7 min readHTML Favicon4 min readHTML Video4 min readLayouts & DesignsHTML Tables10 min readHTML Iframes4 min readHTML Layout4 min readHTML File Paths3 min readProjects & Advanced TopicsHTML Forms5 min readHTML5 Semantics6 min readHTML URL Encoding4 min readHTML Responsive Web Design11 min readTop 10 Projects For Beginners To Practice HTML and CSS Skills8 min readTutorial ReferencesHTML Tags - A to Z List15+ min readHTML Attributes Complete Reference8 min readHTML Global Attributes5 min readHTML5 Complete Reference8 min readHTML5 MathML Complete Reference3 min readHTML DOM Complete Reference15+ min readHTML DOM Audio/Video Complete Reference2 min readSVG Element Complete Reference5 min readSVG Attribute Complete Reference8 min readSVG Property Complete Reference7 min readHTML Canvas Complete Reference4 min read Like