5 // JmesPath is the epresentation of a compiled JMES path query. A JmesPath is
6 // safe for concurrent use by multiple goroutines.
12 // Compile parses a JMESPath expression and returns, if successful, a JMESPath
13 // object that can be used to match against data.
14 func Compile(expression string) (*JMESPath, error) {
16 ast, err := parser.Parse(expression)
20 jmespath := &JMESPath{ast: ast, intr: newInterpreter()}
24 // MustCompile is like Compile but panics if the expression cannot be parsed.
25 // It simplifies safe initialization of global variables holding compiled
27 func MustCompile(expression string) *JMESPath {
28 jmespath, err := Compile(expression)
30 panic(`jmespath: Compile(` + strconv.Quote(expression) + `): ` + err.Error())
35 // Search evaluates a JMESPath expression against input data and returns the result.
36 func (jp *JMESPath) Search(data interface{}) (interface{}, error) {
37 return jp.intr.Execute(jp.ast, data)
40 // Search evaluates a JMESPath expression against input data and returns the result.
41 func Search(expression string, data interface{}) (interface{}, error) {
42 intr := newInterpreter()
44 ast, err := parser.Parse(expression)
48 return intr.Execute(ast, data)