MCPcopy Create free account
hub / github.com/araddon/qlbridge / Validate

Method Validate

expr/builtins/json.go:25–47  ·  view source on GitHub ↗
(n *expr.FuncNode)

Source from the content-addressed store, hash-verified

23
24func (m *JsonPath) Type() value.ValueType { return value.UnknownType }
25func (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
49func jsonPathEval(expression string) expr.EvaluatorFunc {
50 return func(ctx expr.EvalContext, args []value.Value) (value.Value, bool) {

Callers

nothing calls this directly

Calls 2

jsonPathEvalFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected