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 using C#.
C# API for JSON to CSV Conversion
In order 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
Convert a JSON Data or File to CSV
The following are the steps to convert JSON data to CSV format using C#.
- Create a new Workbook object.
- Get reference of the first worksheet using Workbook.Worksheets collection.
- 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 .NET without evaluation limitations.
JSON and CSV files are widely used to store and exchange data within applications. Accordingly, this article covered how to convert JSON data or files to CSV using C#. Besides, you can also explore Aspose.Cells for .NET using the documentation. Also, you can ask your questions via our forum.