using System.Collections.Generic;
using Newtonsoft.Json.Linq;
static void Main(string[] args)
string jsonString = $@"{{
""i4go_expirationyear"": ""2018"",
""i4go_cardtype"": ""VS"",
""i4go_response"": ""SUCCESS"",
""i4go_expirationmonth"": ""04"",
""i4go_uniqueid"": ""1111x1x1x1x1x1x1"",
""expirationmonth"": ""04"",
""errorindicator"": ""N"",
""cgi_host"": ""http://127.0.0.1:16448"",
""secondaryerrorcode"": 0,
""apioptions"": ""ALLDATA"",
""functionrequestcode"": ""E0"",
""tokenserialnumber"": 0,
""expirationyear"": 2018,
""postfinishtime"": 1445822349264,
""cfhttp_statuscode"": ""200 OK"",
""rawline2"": ""0,\""9999999098\"",\""VS\"",\""\"",0.00,\""\"",\""\"",\""\"""",
""reference"": ""WT0000253592"",
""tagstarttime"": 1445822348437,
""trackinformation"": """",
""uniqueid"": ""1111x1x1x1x1x1x1"",
""tagfinishtime"": 1445822349264,
""poststarttime"": 1445822348437,
""preauthorizedamount"": 0,
""i4go_responsecode"": ""1""
Console.Write(JsonToCsv(jsonString));
public static string JsonToCsv(string json)
JObject obj = JObject.Parse(json);
Dictionary<string, string> dict = new Dictionary<string, string>();
AddToDictionary(obj, "", dict);
StringBuilder sb = new StringBuilder();
foreach (KeyValuePair<string, string> pair in dict)
sb.AppendLine(pair.Key + "," + pair.Value);
private static void AddToDictionary(JObject obj, string prefix, Dictionary<string, string> dict)
foreach (var property in obj)
string key = prefix + property.Key;
if (property.Value.Type == JTokenType.Object)
AddToDictionary((JObject)property.Value, key + ".", dict);
string value = property.Value.ToString();
string type = property.Value.Type.ToString();
dict[key] = type + "," + value.Length;