Skip to content

Inconsistent behavior of truthiness in "!!" operator #44

@BohdanCh-w

Description

@BohdanCh-w

While trying out rules on jsonlogic.com, I spotted unexpected behavior when using "!!" operator. Unfortunately, I cannot confirm if that is the problem with JS implementation, used on website, since I am working with an implementation in Go that doesn't support this operator.

The following two rules produce different result:

{
    "if": [
        [0, 1, 2],
        "True",
        "False"
    ]
}

returns "True" as expected

{
    "if": [
        {
            "!!": [0, 1, 2]
        },
        "True",
        "False"
    ]
}

returns "False", which is not what I expected, since any non-empty array should be true per documentation. And !! should correspond to JSONLogic's truthy specs.

I believe that the problem lies in !! as it returns false for any array, which first element is falsy value.
{ "!!": [0, 2, 3] } -> false
{ "!!": ["", "b", "c"] } -> false
{ "!!": [false, true] } -> false
But
{ "!!": [1, 2, 3] } -> true
{ "!!": ["a", "b", "c"] } -> true
{ "!!": [true, false] } -> true

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions