Write JSON Data Into an XLSX/Excel File in JavaScript
Convert your JSON into a .xlsx file and save it

Sometimes, we need to download a .xlsx
file of JSON data.
So, in this article, I will show you how I can create a .xlsx
file using JSON. To do this, let’s create our JSON first. I am keeping my JSON in a sample.json
file and will import it when it’s required.
sample.json
:
Now we have the JSON that we will use to create an XLSX file in our project directory. Now, we need to write our code to create the same.
So, to do this let’s create a file convert.js
and paste the below code:
convert.js
Now we need to install the dependencies, to do this, go to the file location and run the below command:
npm install json2xls

Now that we have installed our dependencies, it’s time to run our app and create the sample.xlsx
file in the same directory.
To do this, run the below command:
node convert.js
After doing this, you can see that the sample.xlsx
file will be created in the same directory.

You can see that the sample.xlsx
file has been created in the below GIF:

Thanks for reading.