From c1775552cc7dfbea9d0633cc03fc13b06881d4ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Sat, 30 Nov 2024 17:22:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=8D=95=E5=85=83=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gjson_hack/path_test.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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) }