We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
System (please complete the following information):
linux
1.20.5
0.6.11
Describe the bug
Wildcard (*) not working in maputil.GetByPath
To Reproduce
My Body from API:
{ "success": true, "result": { "total": 2, "records": [ { "id": "59fab0fa-8f0a-4065-8863-1dae40166015" }, { "id": "7c1bd7f9-2ef4-44c8-9756-2e85156ca58f" } ] } }
This work:
var tcBody := map[string]any{ "success": true, "result.records.0.id": "59fab0fa-8f0a-4065-8863-1dae40166015", "result.records.1.id": "7c1bd7f9-2ef4-44c8-9756-2e85156ca58f", } body, _ := io.ReadAll(response.Body) var resp map[string]any json.Unmarshal(body, &resp) for key, want := range tcBody { val, _ := maputil.GetByPath(key, resp) if val != want { t.Errorf("Body key [%v] was incorrect, got: %v, want: %v", key, val, want) } }
This doesn't work when use wildcard:
var tcBody := map[string]any{ "success": true, "result.records.*.id": []String{ "59fab0fa-8f0a-4065-8863-0dae40166015", "7c1bd7f9-2ef4-44c8-9756-0e85156ca58f", } body, _ := io.ReadAll(response.Body) var resp map[string]any json.Unmarshal(body, &resp) for key, want := range tcBody { val, _ := maputil.GetByPath(key, resp) if val != want { t.Errorf("Body key [%v] was incorrect, got: %v, want: %v", key, val, want) } }
The text was updated successfully, but these errors were encountered:
🐛 fix: maputil - fix wildcard(*) not working on func GetByPath. issues …
4affd6a
…#109
Hi @shurco has been fixed in v0.6.12
val, _ := maputil.GetByPath("result.records.*.id", resp)
Note: !!! the val is []any, not a []string.
[]any
[]string
Sorry, something went wrong.
inhere
No branches or pull requests
System (please complete the following information):
linux
1.20.5
0.6.11
Describe the bug
Wildcard (*) not working in maputil.GetByPath
To Reproduce
My Body from API:
This work:
This doesn't work when use wildcard:
The text was updated successfully, but these errors were encountered: