Skip to content

Limitation: Cannot access root variables inside "some"/"all"/"map" in generated JsonLogic #1303

Description

@datvu-mds

Describe the bug
When using JsonLogic export from react-awesome-query-builder, it is not possible to reference a root-level variable inside array operators such as some, all, or map, due to a limitation in json-logic-js.

For example, the following JsonLogic:

{
  "some": [
    { "var": "multicolor" },
    {
      "in": [
        { "var": "" },
        { "var": "autocompleteMultiple" }
      ]
    }
  ]
}

With data:

{
  "multicolor": [101, 200],
  "autocompleteMultiple": [45, 99, 101, 200]
}

results in false, when it should be true if any value from multicolor appears in autocompleteMultiple.

To Reproduce

  1. Generate a logic as above using react-awesome-query-builder (or manually with json-logic-js).
  2. Run it in the json-logic playground with the provided data.
  3. See that the result is false.

Expected behavior
The logic should correctly evaluate to true if any element of multicolor is contained in autocompleteMultiple.

Additional context

  • This is a known variable-scoping issue with json-logic-js.
  • The root variable context is lost inside the iteration, so { "var": "autocompleteMultiple" } does not access the original data.
  • Workaround: Use filtering and count, for example:
{
  ">": [
    { "size": { "filter": [ { "var": "multicolor" }, { "in": [ { "var": "" }, { "var": "autocompleteMultiple" } ] } ] } },
    0
  ]
}
  • Alternatively, hardcode the array or preprocess the logic/data in application code.
  • Documenting this in limitations will help other users avoid debugging confusion.

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