diff --git a/tool/parse.go b/tool/parse.go index 79f231a..0128731 100644 --- a/tool/parse.go +++ b/tool/parse.go @@ -117,7 +117,11 @@ func GetJSONDataStructWithType(data string) ([]Field, error) { } pathList := make([]Field, 0) r := gjson.Parse(data) + inputIsArr := r.IsArray() r.ForEach(func(key, value gjson.Result) bool { + if inputIsArr && key.Int() > 0 { + return true + } if value.Value() == nil { pathList = append(pathList, Field{ Path: key.String(), @@ -183,6 +187,11 @@ func GetJSONDataStructWithType(data string) ([]Field, error) { return true }) + for idx := 0; idx < len(pathList); idx++ { + if inputIsArr && strings.HasPrefix(pathList[idx].Path, "0.") { + pathList[idx].Path = strings.Replace(pathList[idx].Path, "0.", "[].", 1) + } + } return pathList, nil }