gopkg/safe/data_test.go

43 lines
668 B
Go
Raw Normal View History

2021-03-11 00:05:56 +08:00
// Package safe...
//
// Description : safe...
//
2021-07-25 19:05:59 +08:00
// Author : go_developer@163.com<白茶清欢>
2021-03-11 00:05:56 +08:00
//
// Date : 2021-03-10 10:07 下午
package safe
import (
"fmt"
"testing"
"github.com/tidwall/gjson"
)
func TestFilter(t *testing.T) {
source := []byte(`
{
"name":"zhangdeman",
"age":18,
"extra":{"height":180, "company":"com"}
}
`)
result, err := Filter(source, []string{"name", "extra.company"})
if nil != err {
fmt.Println(err.Error())
} else {
fmt.Println(string(result))
}
}
func TestGJSON(t *testing.T) {
source := `
{
"name":"zhangdeman",
"age":18,
"extra":{"height":180, "company":"com"}
}
`
fmt.Println(gjson.Get(source, "extra.height").Raw)
}