-
Notifications
You must be signed in to change notification settings - Fork 139
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
in operator doesn't support key in object or object in array of objects #27
Comments
Yeah, the problem is that all JsonLogic operators are executed depth-first, except I did this initially because (a) the original spec was all arithmetic and logic operators with no side effects, so no one cared if it did some work that got discarded and (b) it simplifies the internal code for every operator to assume they're working on primitives. (a) stopped being true when I introduced We could pretty easily patch jsonLogic = require('./logic.js');
data = {"stuff":{"a":1, "b":2}};
rule = {"in":["b", {"var":"stuff"}]};
jsonLogic.apply(rule, data); Another improvement might be to increase the rigor of The nuclear option would be to make every command responsible for parsing its own parameters, which would have the advantage of letting you introduce your own control structures and re-uniting the structures at 35-156 and 213-250. I haven't thought deeply about this yet, but I'll bet it has unpleasant externalities. |
The functionality described in #116 would enable someone to write their own operation to achieve this, I believe. |
Currently, "in" supports these cases:
Primitive element in array:
{"in":[ "Ringo", ["John", "Paul", "George", "Ringo"] ]}
Substring in string:
{"in":["Spring", "Springfield"]}
However, if the array you are testing for containment holds objects,
in
doesn't work:{"in": [ {"a": 1}, [ { "a":1 }, { "b":2 } ] ] }
This gives the error
Unrecognized operation a
It seems like it could also support testing for the existence of a key in an object:
{"in": [ "a", { "a":1, "b":2 } ] }
Which also gives the same
Unrecognized operation a
error.The text was updated successfully, but these errors were encountered: