diegoholiveira / jsonlogic

Go Lang implementation of JsonLogic
MIT License
153 stars 44 forks source link

Accessing data using var path inside an array #87

Open cj-f opened 1 month ago

cj-f commented 1 month ago

Hey, not sure if this is best place to post this question, as I don't think it is a problem with the golang jsonlogic as I am noticing the same behavior in go as I do in the play.html page on jsonlogic, but I'm trying to figure out how I can compare array values against data outside of the array

I know that var inside of an array is relative, so { "var": "id" } appears to work, but is there any way I could check that against data outside of the array like the subject.id. If var inside an array is only relative, is the only solution to add a custom operator like absolute_var, if yes, if there any online examples where I could understand how to write an operator like that in golang

Rule: {"some": [{ "var": "attributes.parents" }, {"==": [{ "var": "id" }, { "var": "subject.id" }]}]}

Data: { "subject": { "id": "hugh", }, "attributes": { "parents": [ { "id": "ryan" }, { "id": "hugh" }, ] } }

diegoholiveira commented 1 month ago

@joaoandre do you remember how we solve this issue?

cj-f commented 1 month ago

Actually upon further testing it appears that when using some and the golang jsonlogic pkg, that you can access absolute variable paths, but when using all it does not seem to resolve absolute vars. When testing on https://jsonlogic.com/play.html I notice both all and some do not resolve absolute variables.

So there may be a difference in the golang package with some. I'm currently testing on github.com/diegoholiveira/jsonlogic/v3 v3.5.3

Although I will say I like the behavior of some in go even if it may be a bug, because I want absolute variables to resolve haha, but I would need it to also work with all

cj-f commented 1 month ago

Is the reduce operation also not support in the golang pkg of jsonlogic. I was trying to think of another option if I could get all to work, and figured I could reduce and then cat to build a single string to perform and == check against, but that works on the website, doesn't work using the pkg. Although I just noticed I don't see reduce in the operations.go file

fabianedl777 commented 3 weeks ago

Hi, @cj-f the error you see in json logic is interface conversion: interface {} is map[string]interface {}, not []interface {}