SuperConvert is an open-source lightweight package to convert between JSON, CSV, and Datatables,
It also contains a Hijri date helper (which will be discussed in future articles)
SuperConvert Download
Let's create our project and name it (SuperConvert now is supporting .netcore3.1, .net5, and .net6)
First for converting JSON strings into CSV files we just have to install the SuperConvert package as follows:
Please Install the latest version always.
After installing SuperConvert let's do some coding.
First, we have to type the using statement in order to be able to use the extension methods
//1 Convert json to csv
using SuperConvert.Extentions;
Second, declare the JSON string, we can get it from a file, HTTP, Database .. etc
After getting your JSON List of objects you can use the extension method .ToCsv(), we can pass the path and the file name to the method or we can just call it without parameters (in this case the file will be saved to your application directory)
string jsonStr = "[{\"Id\":\"1\",\"Name\":\"Esam\",\"Gender\":\"Male\",\"Age\":25}," +
"{ \"Id\": \"2\", \"Name\": \"Mohammed\", \"Gender\": \"Male\", \"Age\": 25 }]";
string csvPath = jsonStr.ToCsv();
Console.WriteLine(csvPath);
Another code
The execution will be like
And the excel file saved