rules icon indicating copy to clipboard operation
rules copied to clipboard

How can i evaluate over array?

Open agungwk opened this issue 5 years ago • 4 comments

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

agungwk avatar Nov 23 '20 16:11 agungwk

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.

nikunjy avatar Feb 17 '21 00:02 nikunjy

hey @agungwk did you solve your request?

fcarrero avatar Sep 01 '21 16:09 fcarrero

@nikunjy unable to match strings. It is giving false: log.Println(parser.Evaluate("state eq SIKKIM", map[string]interface{}{"state": "SIKKIM"}))

abdul-saqib avatar Apr 14 '22 09:04 abdul-saqib

@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

nikunjy avatar Apr 17 '22 23:04 nikunjy