gjson的二次处理 #6

Merged
zhangdeman merged 6 commits from feature/json into master 2024-11-29 17:30:35 +08:00
Showing only changes of commit 33815072ea - Show all commits

View File

@ -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{