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

Function jsonPathEval

expr/builtins/json.go:49–69  ·  view source on GitHub ↗
(expression string)

Source from the content-addressed store, hash-verified

47}
48
49func jsonPathEval(expression string) expr.EvaluatorFunc {
50 return func(ctx expr.EvalContext, args []value.Value) (value.Value, bool) {
51 if args[0] == nil || args[0].Err() || args[0].Nil() {
52 return nil, false
53 }
54
55 val := args[0].ToString()
56
57 // Validate that this is valid json?
58 var data interface{}
59 if err := json.Unmarshal([]byte(val), &data); err != nil {
60 return nil, false
61 }
62
63 result, err := jmespath.Search(expression, data)
64 if err != nil {
65 return nil, false
66 }
67 return value.NewValue(result), true
68 }
69}

Callers 1

ValidateMethod · 0.85

Calls 5

NewValueFunction · 0.92
ErrMethod · 0.65
NilMethod · 0.65
ToStringMethod · 0.65
UnmarshalMethod · 0.45

Tested by

no test coverage detected