MCPcopy Create free account
hub / github.com/PaesslerAG/jsonpath / selectValue

Function selectValue

selector.go:66–92  ·  view source on GitHub ↗
(c context.Context, key gval.Evaluable, r, v interface{})

Source from the content-addressed store, hash-verified

64}
65
66func selectValue(c context.Context, key gval.Evaluable, r, v interface{}) (value interface{}, jkey string, err error) {
67 c = currentContext(c, v)
68 switch o := v.(type) {
69 case []interface{}:
70 i, err := key.EvalInt(c, r)
71 if err != nil {
72 return nil, "", fmt.Errorf("could not select value, invalid key: %s", err)
73 }
74 if i < 0 || i >= len(o) {
75 return nil, "", fmt.Errorf("index %d out of bounds", i)
76 }
77 return o[i], strconv.Itoa(i), nil
78 case map[string]interface{}:
79 k, err := key.EvalString(c, r)
80 if err != nil {
81 return nil, "", fmt.Errorf("could not select value, invalid key: %s", err)
82 }
83
84 if r, ok := o[k]; ok {
85 return r, k, nil
86 }
87 return nil, "", fmt.Errorf("unknown key %s", k)
88
89 default:
90 return nil, "", fmt.Errorf("unsupported value type %T for select, expected map[string]interface{} or []interface{}", o)
91 }
92}
93
94//..
95func mapperSelector() ambiguousSelector {

Callers 2

directSelectorFunction · 0.85
multiSelectorFunction · 0.85

Calls 1

currentContextFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…