diff --git a/internal/gojqex/types.go b/internal/gojqex/types.go index 1f9f032a..67344fa7 100644 --- a/internal/gojqex/types.go +++ b/internal/gojqex/types.go @@ -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") } diff --git a/pkg/interp/testdata/value.fqtest b/pkg/interp/testdata/value.fqtest index eb5b4975..150803d1 100644 --- a/pkg/interp/testdata/value.fqtest +++ b/pkg/interp/testdata/value.fqtest @@ -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