Validating 'Type' property in json returns an error
I have a scenario where I need to compare the 'Type' field in json data:
{ "Name": "test", "Type": "Basic" }
My rule is: (I'm using event as the RuleParameter name property)
event.Type == \"Basic\"
The following error is returned:
Exception while parsing expression event.Type == "Basic" - Expression of type 'Newtonsoft.Json.Linq.JTokenType' expected
Works fine if I compare the Name field. Any suggestions?
Implementation
var rules = new List<Rule>();
rules.Add(
new Rule()
{
RuleName = Guid.NewGuid().ToString(),
RuleExpressionType = RuleExpressionType.LambdaExpression,
Expression = "event.Type == \"Basic\""
});
var workflows = new List<Workflow>()
{
new Workflow()
{
WorkflowName = WorkflowName,
Rules = rules
}
};
var deserializedPayload = JsonConvert.DeserializeObject("{\r\n \"Name\": \"test\",\r\n \"Type\": \"Basic\"\r\n}");
var input = new RuleParameter("event", deserializedPayload);
var ruleEngine = new RulesEngine.RulesEngine(workflows.ToArray());
await ruleEngine.ExecuteAllRulesAsync(WorkflowName, input);
It looks like something to do with 'Type' as some reserved keyword. I will check on it and get back to you.
Meanwhile can you try doing event.Type.ToString() == "Basic" and see if that unblocks you?
Thanks, there is a workaround if you use event[\"Type\"] == \"Basic\".