How to convert Excel File data into JSON object in JavaScript?

Today, I will share with you a very small but more helpful tutorial about how to convert excel file data into a JSON object in javascript. you can be done it by xlsx.full.min.js a library of javascript. sometimes we need to upload to excel file and import data to a database. most of the applications done this functionality from the backend side or server-side. but if you want user side done then we can be done it using javascript.

Create index.php file

Simply write the above code in your PHP file and you can be done it.

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />

    <input type="file" id="fileUpload" accept=".xls,.xlsx" /><br />
    <button type="button" id="uploadExcel">Convert</button>
    <pre id="jsonData"></pre>
    var selectedFile;
      .addEventListener("change", function(event) {
        selectedFile =[0];
      .addEventListener("click", function() {
        if (selectedFile) {
          var fileReader = new FileReader();
          fileReader.onload = function(event) {
            var data =;

            var workbook =, {
              type: "binary"
            workbook.SheetNames.forEach(sheet => {
              let rowObject = XLSX.utils.sheet_to_row_object_array(
              let jsonObject = JSON.stringify(rowObject);
              document.getElementById("jsonData").innerHTML = jsonObject;

I hope you like this article.

 Prev post

Next post