using System.Collections;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
public static void Main()
string json = "{\"e\":\"executionReport\",\"E\":1616877261436}";
dynamic result = JsonHelper.Deserialize(json);
Assert.AreEqual("executionReport", result.e);
Assert.AreEqual(1616877261436, result.E);
json = "{\"intValue\":123}";
dynamic newtonSoftResult = JsonHelper.Deserialize(json);
Assert.AreEqual(123, newtonSoftResult.intValue);
string single = "{\"s\":\"String1\",\"f\":\"0.00\"}";
string multiple = "[{\"s\":\"String1\",\"f\":\"0.00\"},{\"s\":\"String2\",\"f\":\"1.23\"}]";
dynamic newtonSingle = JsonHelper.Deserialize(single);
dynamic newtonMultiple = JsonHelper.Deserialize(multiple);
Assert.AreEqual("String1", newtonSingle.s);
Assert.AreEqual("String2", newtonMultiple[1].s);
Assert.IsFalse(newtonSingle is IList);
Assert.IsTrue(newtonMultiple is IList);
Console.WriteLine("All good.");
public static class JsonHelper
public static object Deserialize(string json)
return ToObject(JToken.Parse(json));
private static object ToObject(JToken token)
var expando = new ExpandoObject() as IDictionary<string, object>;
foreach (JProperty prop in token.Children<JProperty>())
expando.Add(prop.Name, ToObject(prop.Value));
return token.Select(ToObject).ToList();
return ((JValue)token).Value;