using Newtonsoft.Json.Linq;
public static void Main()
Test(JToken.Parse("{}"));
Test(JToken.Parse("[]"));
Test(JToken.Parse("\"\""));
Test(JToken.Parse("null"));
private static void Test(JToken token)
Console.WriteLine("Type: " + token.Type.ToString());
Console.WriteLine("Token: " + token.ToString());
Console.WriteLine("IsEmpty1: " + token.IsNullOrEmpty().ToString());
Console.WriteLine("IsEmpty2: " + token.IsNullOrEmpty2().ToString());
public static class JsonHelper
public static bool IsNullOrEmpty(this JToken token)
return (token == null) ||
(token.Type == JTokenType.Array && !token.HasValues) ||
(token.Type == JTokenType.Object && !token.HasValues) ||
(token.Type == JTokenType.String && token.ToString() == String.Empty) ||
(token.Type == JTokenType.Null);
public static bool IsNullOrEmpty2(this JToken token)
return token == null || string.IsNullOrWhiteSpace(token.ToString());