jwadhams/json-logic

Missing basic boolean operator

Closed this issue · 2 comments

I think we need a basic boolean operator to test for truthiness, the opposite of the "!" operator. It appears that currently, one has to use {"if": [{"var": "test"}, true, false]}, which seems unnecessarily verbose. I was going to suggest a unary if operator: {"if": {"var": "test"}}, however it seems the current implementation just returns test in this case. Similar for the and operator. I suppose the operator could simply be named "true," but I really would prefer "if", in spite of breaking BC.

Edit: I was just looking through the json-logic-php source and noticed that it has a "!!" operator. Is this officially a part of the spec? I don't see it documented anywhere, but see that it is in json-logic-js also. It looks like this would do exactly what I am looking for, assuming I can rely on it.

Well I feel dumb. Yes, I consider it an official part of the spec, and I'm adding it to the docs today. Thanks!

It's in the docs!