JSON is a well-known and widely used format to keep and share structured data. Often, it is used to transmit data between different types of applications. CSV, on the other hand, is also used to store the data in a comma separated format. In certain cases, you may need to import data from JSON files to CSV. Therefore, in this article, you will learn how to convert JSON data to CSV programmatically using Python.
Python API for JSON to CSV Conversion
In order to convert JSON data to CSV format, we will use Aspose.Cells for Python via Java. It is a powerful API for creating, modifying, and converting spreadsheet files using Python. You can either download the API or install it using the following pip command.
pip install aspose-cells
Convert a JSON Data or File to CSV
The following are the steps to convert JSON data to CSV format using Python.
- Create a new Workbook object.
- Get reference of the first worksheet using Workbook.getWorksheets().get(0) method.
- Create an object of JsonLayoutOptions class to set additional options.
- Import data from JSON to CSV using JsonUtility.importData() method.
- Save the CSV file using Workbook.save(string, SaveFormat.CSV) method.
The following code sample shows how to convert JSON data to CSV format.
The following is the JSON data that we used in the above code sample.
The following is the converted CSV file.
Get a Free License
Get a temporary license and use Aspose.Cells for Python via Java without evaluation limitations.
JSON and CSV files are widely used to store and transmit the data. In accordance with that, this article covered how to convert JSON data or files to CSV using Python. Furthermore, you can also explore Aspose.Cells for Python via Java using the documentation. Also, you can ask your questions via our forum.