public static string ToJson(this object foo) { try { var s = new JavaScriptSerializer(); return s.Serialize(foo); } catch (Exception e) { return e.Message; } }