diff --git a/gjson_hack/path_test.go b/gjson_hack/path_test.go index d1211bf..65f6180 100644 --- a/gjson_hack/path_test.go +++ b/gjson_hack/path_test.go @@ -10,6 +10,7 @@ package gjson_hack import ( "encoding/json" "fmt" + "github.com/tidwall/gjson" "testing" ) @@ -49,8 +50,27 @@ func TestPathOnlyFinallyPath(t *testing.T) { "email": "xxx@xxx.com", }, "sex": "man", + "user_list": [][]map[string]any{ + []map[string]any{ + {"name": "zhang", "age": 10}, + {"name": "li", "age": 20}, + {"name": "wang", "age": 30}, + }, + []map[string]any{ + {"name": "zhang", "age": 20}, + {"name": "li", "age": 20}, + {"name": "wang", "age": 30}, + }, + []map[string]any{ + {"name": "zhang", "age": 30}, + {"name": "li", "age": 20}, + {"name": "wang", "age": 30}, + }, + }, } byteData, _ := json.Marshal(mapData) + fmt.Println(gjson.GetBytes(byteData, "user_list.#.#.age")) + fmt.Println(gjson.GetBytes(byteData, "user_list.0.0.age")) pathRes, err := Path(string(byteData), &PathOption{ UnfoldArray: false, MaxDeep: 0, @@ -77,6 +97,23 @@ func TestPathOnlyFinallyPathWithUnfoldArray(t *testing.T) { "email": "xxx@xxx.com", }, "sex": "man", + "user_list": [][]map[string]any{ + []map[string]any{ + {"name": "zhang", "age": 10}, + {"name": "li", "age": 20}, + {"name": "wang", "age": 30}, + }, + []map[string]any{ + {"name": "zhang", "age": 10}, + {"name": "li", "age": 20}, + {"name": "wang", "age": 30}, + }, + []map[string]any{ + {"name": "zhang", "age": 10}, + {"name": "li", "age": 20}, + {"name": "wang", "age": 30}, + }, + }, } byteData, _ := json.Marshal(mapData) pathRes, err := Path(string(byteData), &PathOption{