diff --git a/gjson_hack/path.go b/gjson_hack/path.go index 6d8fab7..6ac654c 100644 --- a/gjson_hack/path.go +++ b/gjson_hack/path.go @@ -95,6 +95,7 @@ func doExpandPath(gjsonResult gjson.Result, rootPath string, hasChildren bool, p // 展开数组 for idx, itemRes := range arrayList { doExpandPath(itemRes, rootPath+"."+fmt.Sprintf("%v", idx), true, pathOption, pathResult) + doExpandPath(itemRes, rootPath+".{{idx}}", true, pathOption, pathResult) } } else { // 不展开数组 @@ -107,11 +108,12 @@ func doExpandPath(gjsonResult gjson.Result, rootPath string, hasChildren bool, p return } } - if strings.HasSuffix(rootPath, ".#") { + if strings.HasSuffix(rootPath, ".#") || strings.HasSuffix(rootPath, "{{idx}}") { // 处理不展开类型数组 return } if pathOption.OnlyFinalPath && hasChildren { + // 仅记录最终完整路径, 中间路径不记录 return } if _, exist := pathResult.ValueTable[rootPath]; !exist {