Unable to match data on map[string]struct
simonvadee opened this issue · 1 comments
simonvadee commented
I'm having an issue when executing a JMESPATH query on a map[string]customType
, here's the code :
type testStruct struct {
Value interface{} `json:"value"`
}
func main() {
test1 := map[string]interface{}{
"entry": testStruct{Value: 1},
}
result1, err := jmespath.Search("entry.value", test1)
fmt.Printf("\nerr = %v : res = %+v\n", err, result1) // displays err = nil : res = 1
test2 := map[string]testStruct{
"entry": testStruct{Value: 1},
}
result2, err := jmespath.Search("entry.value", test2)
fmt.Printf("\nerr = %v : res = %+v\n", err, result2) // displays err = nil : res = nil
}
As you can see, a query on a map[string]interface{}
behaves as expected, whereas nil
is returned when executing the same query on a map[string]testStruct
(adding a pointer to testStruct
results in the same output).
Has anyone ever experienced such a problem ?
dpopp07 commented
I'm experiencing this same thing with a map of string to a primitive type e.g. map[string]string
or map[string]int
. When I use map[string]interface{}
, it works fine as you stated. In the other cases, the search always returns nil
.