diff options
-rw-r--r-- | cmd/jp/split.go | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/cmd/jp/split.go b/cmd/jp/split.go index acca93c..2220c37 100644 --- a/cmd/jp/split.go +++ b/cmd/jp/split.go @@ -1,8 +1,6 @@ package main -import ( - "reflect" -) +import "reflect" var indexableKind = map[reflect.Kind]bool{ reflect.Slice: true, @@ -12,15 +10,18 @@ var indexableKind = map[reflect.Kind]bool{ func flatten(in [][]reflect.Value) (out []reflect.Value) { for _, a := range in { for _, v := range a { + if !v.IsValid() { + continue + } if indexableKind[v.Kind()] { sub := make([]reflect.Value, v.Len()) for j := 0; j < v.Len(); j++ { - sub = append(sub, v.Index((j))) + sub = append(sub, v.Index(j)) } out = append(out, flatten([][]reflect.Value{sub})...) continue } - if v.IsValid() && v.CanInterface() { + if v.CanInterface() { if sub, ok := v.Interface().([]interface{}); ok { for i := range sub { out = append(out, reflect.ValueOf(sub[i])) |