diff --git a/arrays.go b/arrays.go index e7c4f03..559c166 100644 --- a/arrays.go +++ b/arrays.go @@ -66,7 +66,7 @@ func _map(values, data interface{}) interface{} { for _, value := range subject.([]interface{}) { v := parseValues(logic, value) - if isTrue(v) || isNumber(v) { + if isTrue(v) || isNumber(v) || isBool(v) { result = append(result, v) } } diff --git a/internal/issues/0083_test.go b/internal/issues/0083_test.go new file mode 100644 index 0000000..01fcc1e --- /dev/null +++ b/internal/issues/0083_test.go @@ -0,0 +1,37 @@ +package issues_test + +import ( + "bytes" + "strings" + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/diegoholiveira/jsonlogic/v3" +) + +func TestIssue83(t *testing.T) { + rule := `{ + "map": [ + {"var": "listOfLists"}, + {"in": ["item_a", {"var": ""}]} + ] + }` + + data := `{ + "listOfLists": [ + ["item_a", "item_b", "item_c"], + ["item_b", "item_c"], + ["item_a", "item_c"] + ] + }` + + var result bytes.Buffer + + err := jsonlogic.Apply(strings.NewReader(rule), strings.NewReader(data), &result) + + if assert.Nil(t, err) { + expected := `[true,false,true]` + assert.JSONEq(t, expected, result.String()) + } +}