acme-dns/vendor/github.com/yalp/jsonpath/example_test.go

46 lines
647 B
Go
Raw Normal View History

2018-01-22 16:19:33 +07:00
package jsonpath_test
import (
"encoding/json"
"fmt"
"github.com/yalp/jsonpath"
)
func ExampleRead() {
raw := []byte(`{"hello":"world"}`)
var data interface{}
json.Unmarshal(raw, &data)
out, err := jsonpath.Read(data, "$.hello")
if err != nil {
panic(err)
}
fmt.Print(out)
// Output: world
}
func ExamplePrepare() {
raw := []byte(`{"hello":"world"}`)
helloFilter, err := jsonpath.Prepare("$.hello")
if err != nil {
panic(err)
}
var data interface{}
if err = json.Unmarshal(raw, &data); err != nil {
panic(err)
}
out, err := helloFilter(data)
if err != nil {
panic(err)
}
fmt.Print(out)
// Output: world
}