How to convert Excel XLSX into JSON in Python

I don’t think anybody has ever been keen about the prospect of coding around format conversions. It’s very dry, but it is quite necessary. To solve this problem, I present to you this lovely API that will allow you to convert between XLSX and JSON without the boring part. Here we go.

Install the client for the API with pip install:

pip install cloudmersive-convert-api-client

Calling convert_data_xlsx_to_json comes next.

from __future__ import print_functionimport timeimport cloudmersive_convert_api_clientfrom import ApiExceptionfrom pprint import pprint# Configure API key authorization: Apikeyconfiguration = cloudmersive_convert_api_client.Configuration()configuration.api_key['Apikey'] = 'YOUR_API_KEY'# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed# configuration.api_key_prefix['Apikey'] = 'Bearer'# create an instance of the API classapi_instance = cloudmersive_convert_api_client.ConvertDataApi(cloudmersive_convert_api_client.ApiClient(configuration))input_file = '/path/to/file' # file | Input file to perform the operation on.try:# Convert Excel XLSX to JSON conversionapi_response = api_instance.convert_data_xlsx_to_json(input_file)pprint(api_response)except ApiException as e:print("Exception when calling ConvertDataApi->convert_data_xlsx_to_json: %s\n" % e)

And just like that, you can now make your file conversions. It really is that simple. Our APIs offer a ton of other solutions, too. If you need to then convert your JSON into XML, for example, you can apply convert_data_json_to_xml. Same easy process.

Image for post
Image for post

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store