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
- Generate a logic as above using react-awesome-query-builder (or manually with json-logic-js).
- Run it in the json-logic playground with the provided data.
- 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.
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, ormap, 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 betrueif any value frommulticolorappears inautocompleteMultiple.To Reproduce
false.Expected behavior
The logic should correctly evaluate to
trueif any element ofmulticoloris contained inautocompleteMultiple.Additional context
{ "var": "autocompleteMultiple" }does not access the original data.{ ">": [ { "size": { "filter": [ { "var": "multicolor" }, { "in": [ { "var": "" }, { "var": "autocompleteMultiple" } ] } ] } }, 0 ] }