From 5e0dd1c14566942977a8f203c50c4f2e543b3d9f Mon Sep 17 00:00:00 2001 From: Mohamed Shapan Date: Wed, 1 Jul 2020 08:24:24 +0200 Subject: [PATCH] resolve #1 unmarshaling into array of objects --- unmarshal.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/unmarshal.go b/unmarshal.go index 13e8775..2d37b3f 100644 --- a/unmarshal.go +++ b/unmarshal.go @@ -58,9 +58,17 @@ func unmarshalSlice(results []gjson.Result, field reflect.Type) interface{} { newSlice := reflect.MakeSlice(field, 0, 0) for i := 0; i < len(results); i++ { - v := parseDataType(results[i], field.Elem().String()) - if v != nil { - newSlice = reflect.Append(newSlice, reflect.ValueOf(v)) + + var value interface{} + if isStructureType(field.Kind().String()) { + value = parseStructureType(results[i], field.Elem()) + } else { + // set field value depend on it's data type + value = parseDataType(results[i], field.Kind().String()) + } + + if value != nil { + newSlice = reflect.Append(newSlice, reflect.ValueOf(value)) } }