(n *expr.FuncNode)
| 23 | |
| 24 | func (m *JsonPath) Type() value.ValueType { return value.UnknownType } |
| 25 | func (m *JsonPath) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error) { |
| 26 | if len(n.Args) != 2 { |
| 27 | return nil, fmt.Errorf(`Expected 2 args for json.jmespath(field,json_val) but got %s`, n) |
| 28 | } |
| 29 | |
| 30 | jsonPathExpr := "" |
| 31 | switch jn := n.Args[1].(type) { |
| 32 | case *expr.StringNode: |
| 33 | jsonPathExpr = jn.Text |
| 34 | default: |
| 35 | return nil, fmt.Errorf("expected a string expression for jmespath got %T", jn) |
| 36 | } |
| 37 | |
| 38 | parser := jmespath.NewParser() |
| 39 | _, err := parser.Parse(jsonPathExpr) |
| 40 | if err != nil { |
| 41 | // if syntaxError, ok := err.(jmespath.SyntaxError); ok { |
| 42 | // u.Warnf("%s\n%s\n", syntaxError, syntaxError.HighlightLocation()) |
| 43 | // } |
| 44 | return nil, err |
| 45 | } |
| 46 | return jsonPathEval(jsonPathExpr), nil |
| 47 | } |
| 48 | |
| 49 | func jsonPathEval(expression string) expr.EvaluatorFunc { |
| 50 | return func(ctx expr.EvalContext, args []value.Value) (value.Value, bool) { |
nothing calls this directly
no test coverage detected