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

interp: Allow and convert JQValues:s (ex decode value) in function ar… #638

Merged
merged 1 commit into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions internal/gojqex/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,22 +124,11 @@ func CastFn[T any](v any, structFn func(input any, result any) error) (T, bool)
default:
ft := reflect.TypeOf(&t)
if ft.Elem().Kind() == reflect.Struct {
m := map[string]any{}
switch v := v.(type) {
case map[string]any:
m = v
case nil:
// nop use instantiated map
case gojq.JQValue:
if jm, ok := Cast[map[string]any](v.JQValueToGoJQ()); ok {
m = jm
} else {
return t, false
}
default:
// TODO: some way to allow decode value passthru?
m, ok := ToGoJQValue(v)
if !ok {
return t, false
}

if structFn == nil {
panic("structFn nil")
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/interp/testdata/value.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,8 @@ mp3> .headers._index
error: expected a extkey but got: _index
mp3> ._index
error: expected a extkey but got: _index
mp3> .headers[0].header.version as $r | {a:12} | tojson({indent: $r}) | println
{
"a": 12
}
mp3> ^D