diff --git a/gjson_hack/path_test.go b/gjson_hack/path_test.go index 16a6211..8bd5f64 100644 --- a/gjson_hack/path_test.go +++ b/gjson_hack/path_test.go @@ -12,6 +12,8 @@ import ( "fmt" "testing" + "github.com/tidwall/sjson" + "github.com/tidwall/gjson" ) @@ -168,6 +170,12 @@ func TestExpandArrayPath(t *testing.T) { PathList: nil, PathMap: nil, } - ExpandArrayPath(jsonStr, "user_list.{{idx}}.{{idx}}.age", "", pathExpendRes) - fmt.Println(pathExpendRes) + ExpandArrayPath(jsonStr, "user_list.{{idx}}.{{idx}}.age", "a.{{idx}}.{{idx}}.b", pathExpendRes) + ExpandArrayPath(jsonStr, "user_list.{{idx}}.{{idx}}.name", "a.{{idx}}.{{idx}}.c", pathExpendRes) + ExpandArrayPath(jsonStr, "user_list.{{idx}}.{{idx}}.sex", "a.{{idx}}.{{idx}}.c", pathExpendRes) + res := "" + for _, item := range pathExpendRes.PathList { + res, _ = sjson.Set(res, pathExpendRes.PathMap[item], gjson.Get(jsonStr, item).Value()) + } + fmt.Println(res) }