Skip to content

Commit

Permalink
resolve #1 unmarshaling into array of objects
Browse files Browse the repository at this point in the history
  • Loading branch information
m7shapan committed Jul 1, 2020
1 parent 2d95136 commit 5e0dd1c
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down

0 comments on commit 5e0dd1c

Please sign in to comment.