using System.Collections.Generic;
using Newtonsoft.Json.Linq;
public static void Main()
var json = @"{ 'array': [ 1, 2, 3 ], 'boolean': true, 'number': 123, 'object': { 'a': 'b', 'c': 'd', 'e': 'f' }, 'date': '2014-01-01T23:28:56.782Z', 'string': 'Hello World', 'null': null, 'emptyString': '', 'emptyObject': {}, 'emptyArray': [] }";
JObject jObj = JObject.Parse(json);
var json2 = @"{ 'array': [ 1, 2, 3 ], 'number': 123, 'object': { 'a': 'b', 'c': 'd', 'e': 'f' }, 'date': '2014-01-01T23:28:56.782Z', 'boolean': true, 'string': 'Hello World', 'null': null, 'emptyString': '', 'emptyObject': {}, 'emptyArray': [] }";
JObject jObj2 = JObject.Parse(json);
var flattened = jObj.Flatten();
WriteLine(jObj.Flatten().Unflatten().EqualTo(jObj2));
WriteLine(jObj.Flatten().Unflatten().EqualTo(json2));
public static Action<object> WriteLine = (msg) => Console.WriteLine("\r\n" + msg.ToString() + "\r\n");
public static string ToDebugString<TKey, TValue>(IDictionary<TKey, TValue> dictionary) => "{\r\n\t" + string.Join(",\r\n\t", dictionary.Select(kv => kv.Key + " = " + kv.Value).ToArray()) + "\r\n}";
public static class ObjectHelpers
public static string SerializeObject<T>(this T toSerialize) => JsonConvert.SerializeObject(toSerialize, new JsonSerializerSettings()
Formatting = Formatting.None
public static bool EqualTo(this object obj, object toCompare)
var tempObj = obj is string
? JObject.Parse((string)obj)
: JToken.FromObject(obj);
var tempToCompare = toCompare is string
? JObject.Parse((string)toCompare)
: JToken.FromObject(toCompare);
return JToken.DeepEquals(tempObj, tempToCompare);
public static bool IsBlank<T>(this T obj) where T : new()
return newObj.SerializeObject() == blank.SerializeObject();