
JSON files are immensely used to store and transmit structured data. However, in certain cases, you may need to import data from JSON files to Excel spreadsheets. To achieve this programmatically, this article covers how to convert JSON files to Excel XLSX or XLS format on the Linux platform.
API to Import Data from JSON to Excel on Linux
Aspose.Cells for Java is a robust, feature‑rich API that enables creation, manipulation, and conversion of spreadsheet documents with high fidelity. It supports Linux environments and provides dedicated classes for handling JSON data. You can obtain the library as a downloadable JAR file or add it to your Maven project with the repository and dependency definitions below.
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.com/repo/</url>
</repository>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-cells</artifactId>
<version>21.9</version>
</dependency>
Import JSON Data to Excel on Linux
Follow these detailed steps to transform a JSON file into an Excel worksheet on Linux:
- Read the JSON file – Load the entire JSON content into a
Stringvariable. - Create a workbook – Instantiate the
Workbookclass, which represents an Excel file. - Select the target worksheet – Retrieve the first
Worksheetobject from the workbook where the data will be placed. - Configure layout options – Create a
JsonLayoutOptionsobject to control how arrays and objects are rendered. - Set array handling – Use
JsonLayoutOptions.setArrayAsTable(true)to import JSON arrays as Excel tables. - Import the JSON data – Call
JsonUtility.importData(jsonString, worksheet.getCells(), 0, 0, layoutOptions)to populate the worksheet. - Save the workbook – Persist the workbook to disk in either XLSX or XLS format with
Workbook.save(filePath, SaveFormat.XLSX)(orSaveFormat.XLS).
The code snippet below demonstrates the complete process in Java.
Get a Free License
You can use Aspose.Cells for Java without evaluation limitations by obtaining a temporary license.
Conclusion
This guide showed how to import JSON data into Excel XLSX or XLS files on a Linux system using Aspose.Cells for Java. For deeper integration, explore the full documentation or ask questions in the forum.