Click or drag to resize
Json.NET

Create JSON using Collection Initializers

 

This sample creates JObject and JArray instances using the C# collection initializer syntax.

Sample
Usage
JObject o = new JObject
{
    { "Cpu", "Intel" },
    { "Memory", 32 },
    {
        "Drives", new JArray
        {
            "DVD",
            "SSD"
        }
    }
};

Console.WriteLine(o.ToString());
// {
//   "Cpu": "Intel",
//   "Memory": 32,
//   "Drives": [
//     "DVD",
//     "SSD"
//   ]
// }