I am using Newtonsoft’s Json.NET to deserialize a JSON string:
var output = JsonConvert.DeserializeObject<dynamic>("{ 'foo': 'bar' }");
How can I check that output is empty? An example test case:
var output = JsonConvert.DeserializeObject<dynamic>("{ }");
Assert.IsNull(output); // fails
The object you get back from DeserializeObject is going to be a JObject, which has a
Countproperty. This property tells you how many properties are on the object.This won’t tell you if a dynamic object is empty, but it will tell you if a deserialized JSON object is empty.