Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active October 4, 2021 09:14
Show Gist options
  • Save aspose-com-gists/a22c8d99c0265e8bf2e30473c6ecb824 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/a22c8d99c0265e8bf2e30473c6ecb824 to your computer and use it in GitHub Desktop.
Convert JSON to CSV in C#
// load JSON data
string jsonInput = "[{'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}]";
// create a blank Workbook object
var workbook = new Workbook();
// access default empty worksheet
var worksheet = workbook.Worksheets[0];
// set JsonLayoutOptions for formatting
var layoutOptions = new JsonLayoutOptions();
layoutOptions.ArrayAsTable = true;
// import JSON data to CSV
JsonUtility.ImportData(jsonInput, worksheet.Cells, 0, 0, layoutOptions);
// save CSV file
workbook.Save("output.csv", SaveFormat.CSV);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment