using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.ComponentModel;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
public int Mushrooms { get; set; }
public int Olives { get; set; }
public int Zucchini { get; set; }
public int Pepperoni { get; set; }
public int ShouldNotBeHere1 { set { shouldNotBeHere1 = value; } }
public int ShouldNotBeHere2 { set { shouldNotBeHere2 = value; } private get { return shouldNotBeHere2; } }
public int this[int index]
public static int ShouldNotBeHere3 { get; set; }
public List<Names> cols { get; set; }
public List<Row> rows { get; set; }
public string label { get; set; }
public string type { get; set; }
public List<C> c { get; set; }
public object v { get; set; }
static string GetDesiredJson()
public static void Test()
var types = new Type { Mushrooms = 3, Olives = 31, Zucchini = 1, Pepperoni = 2 };
var query = types.GetType()
.GetProperties(BindingFlags.Instance | BindingFlags.Public)
.Where(p => p.GetIndexParameters().Length == 0 && p.GetGetMethod() != null && p.CanRead)
.Select(p => new Row { c = new List<C> { new C { v = p.Name }, new C { v = p.GetValue(types, new object[0]) } } });
var root = new Rootobject
cols = new List<Names> { new Names { label = "Types", type = "string" }, new Names { label = "values", type = "number" } },
var json = JsonConvert.SerializeObject(root, Formatting.Indented);
Console.WriteLine("Initial object: ");
Console.WriteLine(JsonConvert.SerializeObject(types, Formatting.Indented));
Console.WriteLine("Serialized JSON: ");
var desiredJson = GetDesiredJson();
if (!JToken.DeepEquals(JToken.Parse(desiredJson), JToken.Parse(json)))
throw new InvalidOperationException("!JToken.DeepEquals(JToken.Parse(desiredJson), JToken.Parse(json))");
Console.WriteLine("Desired and actual JSON are equivalent.");
public static void Main()
Console.WriteLine("Json.NET version: " + typeof(JsonSerializer).Assembly.FullName);