gjson读取参数支持key名称中包含.

This commit is contained in:
2024-12-04 20:50:13 +08:00
parent 355144b623
commit 48639ba59a
3 changed files with 101 additions and 0 deletions

View File

@ -179,3 +179,20 @@ func TestExpandArrayPath(t *testing.T) {
}
fmt.Println(res)
}
func TestGet(t *testing.T) {
mapData := map[string]any{
"person.name": "test",
"test": map[string]any{
"a.b": "c",
"d.e": map[string]any{
"e.f": "g",
},
},
}
byteData, _ := json.Marshal(mapData)
gjsonResult := gjson.ParseBytes(byteData)
fmt.Println(Get(gjsonResult, "{{#person.name#}}").String())
fmt.Println(Get(gjsonResult, "test.{{#a.b#}}").String())
fmt.Println(Get(gjsonResult, "test.{{#d.e#}}.{{#e.f#}}").String())
}