using System.Collections.Generic;
using Newtonsoft.Json.Linq;
public static void Main()
JObject jObj = JObject.Parse(json);
var flattened = jObj.Flatten();
WriteLine("flattened dictionary: " + ToDebugString(flattened));
JObject unflattened = flattened.Unflatten();
WriteLine("Original JObject is equal to unflattened dictionary: " + JToken.DeepEquals(jObj, unflattened));
public static Action<object> WriteLine = (msg) => Console.WriteLine("\r\n" + msg.ToString() + "\r\n");
public static string ToDebugString<TKey, TValue>(IDictionary<TKey, TValue> dictionary)
return "{\r\n\t" + string.Join(",\r\n\t", dictionary.Select(kv => kv.Key + " = " + kv.Value).ToArray()) + "\r\n}";