Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Jsonpath ¶
Jsonpath will evaluate the provided jsonpath on the provided json. It does not cache either of these parameters. If you are using the same jsonpath consistently then you would want to create an Evaluator for that path instead. An error is returned if there is a problem parsing the jsonpath or if the json could not be parsed.
Example ¶
ExampleJsonpath is a simple example on how to extract a single field from each object in an array using jsonpath.
const jsonString = `{ "firstName": "John", "lastName" : "doe", "age" : 26, "address" : { "streetAddress": "naist street", "city" : "Nara", "postalCode" : "630-0192" }, "phoneNumbers": [ { "type" : "iPhone", "number": "0123-4567-8888" }, { "type" : "home", "number": "0123-4567-8910" }, { "type": "mobile", "number": "0913-8532-8492" } ] }` result, err := Jsonpath([]byte(jsonString), "$.phoneNumbers[*].type") if err != nil { log.Fatal(err) } for _, item := range result { fmt.Println(item) }
Output: iPhone home mobile
Types ¶
type Evaluator ¶
type Evaluator struct {
// contains filtered or unexported fields
}
Evaluator is a compiled form of a jsonpath. It can run it's jsonpath against any provided json object and only needs to parse the provided json.
func NewEvaluator ¶
NewEvaluator will compile the provided jsonpath and create an object that can run that expression on provided json objects. If the path is not valid then an error is returned.