JSON to CSV in C#

JSON is an immensely used format to store structured data. In various cases, JSON files are used to transmit data between applications. Alongside, CSV is also used to store the data as comma-separated values. In this article, you will learn how to import data from JSON files to CSV programmatically. Particularly, the article will cover how to convert JSON data to CSV in C#.

JSON to CSV C# Converter - Free Download

To convert JSON data to CSV, we will use Aspose.Cells for .NET. It is a powerful API for creating, modifying, and converting spreadsheet files from within .NET applications. You can either download the API or install it using NuGet.

PM> Install-Package Aspose.Cells

How to Convert JSON to CSV in C#

Aspose.Cells for .NET provides the easiest way of converting JSON files to CSV format. Below are the steps to perform this conversion.

  • Create a new Excel file.
  • Read data from JSON file.
  • Import JSON data into the Excel file and save it in CSV format.

Let’s now write the C# code to convert a JSON file to CSV format.

Save JSON File as CSV in C#

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

The following code sample shows how to export JSON data to CSV in C#.

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 converted CSV file.

JSON to CSV

API to Export JSON Data to CSV in C# - Get a Free License

Get a free temporary license and export JSON files to CSV format without evaluation limitations.

Read More - C# JSON to CSV Converter

You can also explore Aspose.Cells for .NET using the documentation. Also, you can ask your questions via our forum.

Conclusion

JSON and CSV files are widely used to store and exchange data within applications. Accordingly, this article covered how to convert JSON files to CSV format in C#. You can easily integrate the provided code sample into your application and export JSON data to CSV files.

See Also