JSON to CSV in Java

JSON files are widely used to store and transmit structured data between applications. On the other hand, CSV is also utilized to store the data, such as datasets, as comma-separated values. In this article, you will learn how to export data from JSON files to CSV programmatically. More specifically, the article will cover how to convert JSON to CSV in Java.

Java JSON to CSV Converter - Free Download

Aspose.Cells for Java is a powerful API to create and manipulate spreadsheet documents from within the Java applications. We will use this API to convert the JSON data to CSV format. You can either download Aspose.Cells for Java or install it using the following Maven configurations.

<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>

Steps to Convert JSON Data to CSV in Java

Aspose.Cells provides a high-speed and high-fidelity conversion of JSON files to CSV format in Java. The following are the steps to save the JSON data in CSV format using the API.

  • Create a new Excel workbook and select the desired worksheet.
  • Import Data from JSON to Excel worksheet.
  • Save Excel workbook in CSV format.

Now, let’s have a look at how to perform these steps for JSON to CSV conversion using Java code.

Convert JSON to CSV in Java

The following are the steps to convert JSON data to CSV format using Java.

The following code sample shows how to convert JSON data to CSV format.

JSON Data

The following is the JSON data that we used in the above code sample.

[{"nodeId":1,"reputation":1134},{"nodeId":2,"reputation":547},{"nodeId":3,"reputation":1703},{"nodeId":4,"reputation":-199},{"nodeId":5,"reputation":-306},{"nodeId":6,"reputation":-49},{"nodeId":7,"reputation":1527},{"nodeId":8,"reputation":1223}]'

Converted CSV

The following is the screenshot of the data converted to CSV format.

JSON to CSV

Java JSON to CSV Converter API - Get a Free License

You can get a temporary license and use Aspose.Cells for Java without evaluation limitations.

Conclusion

JSON and CSV files are immensely used to keep and exchange data. Often, you need to export data from JSON files to CSV programmatically. For such cases, this article covered how to convert JSON data to CSV in Java. Alongside, you can also explore Aspose.Cells for Java using the documentation. In addition, you can ask your questions via our forum.

See Also