Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to match data on map[string]struct #32

Open
simonvadee opened this issue Jul 3, 2018 · 1 comment
Open

Unable to match data on map[string]struct #32

simonvadee opened this issue Jul 3, 2018 · 1 comment

Comments

@simonvadee
Copy link

simonvadee commented Jul 3, 2018

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
Copy link

dpopp07 commented Jun 11, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants