using Newtonsoft.Json.Linq;
public static class JsonExtensions
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 string conditionJSON = "{\"text\":{\"if\":[{\"===\":[{\"var\":\"Features.FramedShelf\"},{\"var\":\"Features.FramedSeat\"},true]},\"How many framed shelves are there?\",{\"===\":[{\"var\":\"Features.FramedShelf\"},true]},\"How many framed shelves are there?\",{\"===\":[{\"var\":\"Features.FramedSeat\"},true]},\"How many framed seats are there?\"]}}";
public Features Features { get; set; }
public bool FramedSeat { get; set; }
public bool FramedShelf { get; set; }
public JObject DataSource { get; set; }
public BathUnit BathUnit { get; set; }
private readonly JsonLogicEvaluator _evaluator = new JsonLogicEvaluator(EvaluateOperators.Default);
var result = DataSource["text"];
if (result.IsNullOrEmpty())
return _evaluator.Apply(result, JsonConvert.SerializeObject(BathUnit)).ToString();
public static void Main()
var model = new Model{DataSource = JObject.Parse(conditionJSON), BathUnit = new BathUnit{Features = new Features{FramedSeat = true, FramedShelf = false}}};
Console.WriteLine(model.Text);