json-logic-js
json-logic-js copied to clipboard
Referencing data values within a map
This is probably a newbie question and I searched but couldn't find a relevant resolved issue. I have the need to write an expression that references data values outside of the array within a map expression:
Logic: { "map": [{ "var": "ROOT.TESTS" }, { ">=": [{ "var": "RATE" }, { "var": "ROOT.TARGET" }] } ] }
Data: { "ROOT": { "TARGET": 23, "TESTS": [ { "ID": 1, "RATE": 22 }, { "ID": 2, "RATE": 23 } ] } }
Here I want to find the tests where the test rate value exceeds the target value. Is there any way to reference data values within a map expression that are outside of the data being mapped? Or is there some other approach I could use to accomplish this?
Hey, this currently is not supported in json-logic-js.
I created issue #91 a while back to potentially explore this functionality.
I loathe being a nuisance and shilling for a project that I'm supporting, but json-logic-engine supports this functionality.
Using the logic:
{
"map": [
{
"var": "ROOT.TESTS"
},
{
">=": [
{
"var": "RATE"
},
{
"var": "../../ROOT.TARGET"
}
]
}
]
}
And the data you provided, the result computed is [false, true]