MCPcopy Create free account
hub / github.com/cel-expr/cel-go / jsonEncodeValue

Function jsonEncodeValue

ext/encoders.go:139–153  ·  view source on GitHub ↗
(val ref.Val)

Source from the content-addressed store, hash-verified

137}
138
139func jsonEncodeValue(val ref.Val) (string, error) {
140 native, err := val.ConvertToNative(types.JSONValueType)
141 if err != nil {
142 return "", err
143 }
144 jsonValue, ok := native.(*structpb.Value)
145 if !ok {
146 return "", fmt.Errorf("cannot convert %T to JSON value", native)
147 }
148 jsonBytes, err := protojson.Marshal(jsonValue)
149 if err != nil {
150 return "", err
151 }
152 return string(jsonBytes), nil
153}

Callers 1

CompileOptionsMethod · 0.85

Calls 1

ConvertToNativeMethod · 0.65

Tested by

no test coverage detected