How to convert .json file to excel in C #

I want to convert a .json file to excel. iam cannot find a solution anywhere for this problem using C # language. Can anyone help me with them along with the exact solution.

+4
source share
2 answers

Here is another partial solution that does not require json if json is in table format.

DataTable dt = (DataTable)JsonConvert.DeserializeObject(json, (typeof(DataTable)));

Here you can use any of the many datatable → excel solutions available on the Internet.

Many are published here: How to Export a DataTable to Excel

+6
source

, Excel. Json.NET CSV , Excel.

JSON...

[{
    "foo": "bar"
}]

Json.NET , #

var jsonData = "[{ \"foo\": \"bar\" }]";

var jsonDefinition = new object[]
{
    new {foo = ""}
};

var result = JsonConvert.DeserializeAnonymousType(jsonData, jsonDefinition);

, CSV.

var sb = new StringBuilder();
foreach (dynamic o in result)
{
    sb.AppendLine(o.foo);
}
File.WriteAllText(@"c:\code\test.csv", sb.ToString());
+3

All Articles