How to convert Excel XLSX into JSON in Node.JS

There is a common need for conversion between an Excel spreadsheet and JSON format. Setting this up would normally be rather arduous even under the best of circumstances. To counteract this, we propose using this alternative method, involving an API.

With the following dependency reference added to package.json, we can install our client.

"dependencies": {
"cloudmersive-convert-api-client": "^2.1.6"

When that’s done, we will carry on with the calling of our function, in this case, convertDataXlsxToJson. Here’s some sample code for this to get you started.

var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';var apiInstance = new CloudmersiveConvertApiClient.ConvertDataApi();var inputFile = "/path/to/file"; // File | Input file to perform the operation on.var callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.convertDataXlsxToJson(inputFile, callback);

And there you have it. Now we only have to input an XLSX file, with our response being the corresponding JSON version.

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.