using Newtonsoft.Json.Linq;
public static void Main()
ParseAndProcess("First run", @"{ ""nested"": ""foo"" }");
ParseAndProcess("Second run", @"{ ""nested"": null }");
ParseAndProcess("Third run", @"{ }");
private static void ParseAndProcess(string comment, string json)
Console.WriteLine("--- " + comment + " ---");
JToken root = JToken.Parse(json);
JToken nested = root["nested"];
if (nested.Type == JTokenType.Null)
Console.WriteLine("nested is set to null");
Console.WriteLine("nested has a value: " + nested.ToString());
Console.WriteLine("nested does not exist");