How can i evaluate over array?
Hello,
how can i evaluate the value inside array? maybe for some object like this
{
"data": [
{ "key": "val1" },
{ "key": "val2" },
...
]
}
evaluate the object like this
data.key == "val1"
Thanks in advance
There are only some kind of lists supported https://github.com/nikunjy/rules/blob/master/parser/JsonQuery.g4#L67
You or I would have to extend the gram to support list of objects. It would probably be a lot of work to support any kind of arbitrary objects.
hey @agungwk did you solve your request?
@nikunjy unable to match strings.
It is giving false: log.Println(parser.Evaluate("state eq SIKKIM", map[string]interface{}{"state": "SIKKIM"}))
@asaqib27 for a completely different question please file a new issue. To answer your question your test does not work because your rules is not written correctly. Write this instead
parser.Evaluate(`state eq "SIKKIM"`, map[string]interface{}{
"state": "SIKKIM",
})
You can find many more examples here https://github.com/nikunjy/rules/blob/3feb5e7e0e4b4e96558c31fc3d198363f5319203/parser/parse_simple_test.go#L1046