Convert JSON to CSV

Convert JSON to CSV

Aspose.Cells supports converting simple as well as nested JSON to CSV. For this, the API provides JsonLayoutOptions and JsonUtility classes. The JsonLayoutOptions class provides the options for JSON layout like IgnoreArrayTitle(ignores the title if the array is a property of an object) or ArrayAsTable(processes the array as a table). The JsonUtility class processes the JSON using the layout options set with the JsonLayoutOptions class.

The following code sample demonstrates the use of JsonLayoutOptions and JsonUtility classes to load the source JSON file and generates the output CSV file.

Sample Code

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//Source directory
string sourceDir = RunExamples.Get_SourceDirectory();
//Output directory
string outputDir = RunExamples.Get_OutputDirectory();
// Read JSON file
string str = File.ReadAllText(sourceDir + "SampleJson.json");
// Create empty workbook
Workbook workbook = new Workbook();
// Get Cells
Cells cells = workbook.Worksheets[0].Cells;
// Set JsonLayoutOptions
JsonLayoutOptions importOptions = new JsonLayoutOptions();
importOptions.ConvertNumericOrDate = true;
importOptions.ArrayAsTable = true;
importOptions.IgnoreTitle = true;
JsonUtility.ImportData(str, cells, 0, 0, importOptions);
// Save Workbook
workbook.Save(outputDir + @"SampleJson_out.csv");