Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can i evaluate over array? #18

Open
agungwk opened this issue Nov 23, 2020 · 4 comments
Open

How can i evaluate over array? #18

agungwk opened this issue Nov 23, 2020 · 4 comments

Comments

@agungwk
Copy link

agungwk commented Nov 23, 2020

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

@nikunjy
Copy link
Owner

nikunjy commented Feb 17, 2021

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.

@fcarrero
Copy link

fcarrero commented Sep 1, 2021

hey @agungwk did you solve your request?

@ericbrown30
Copy link

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

@nikunjy
Copy link
Owner

nikunjy commented Apr 17, 2022

@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

func TestString(t *testing.T) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants