MCPcopy Create free account
hub / github.com/jmespath/go-jmespath / toArrayStr

Function toArrayStr

util.go:164–178  ·  view source on GitHub ↗

ToArrayStr converts an empty interface type to a slice of strings. If any element in the array cannot be converted, then nil is returned along with a second value of false. If the input data could be entirely converted, then the converted data, along with a second value of true, will be returned.

(data interface{})

Source from the content-addressed store, hash-verified

162// converted, then the converted data, along with a second value of true,
163// will be returned.
164func toArrayStr(data interface{}) ([]string, bool) {
165 // Is there a better way to do this with reflect?
166 if d, ok := data.([]interface{}); ok {
167 result := make([]string, len(d))
168 for i, el := range d {
169 item, ok := el.(string)
170 if !ok {
171 return nil, false
172 }
173 result[i] = item
174 }
175 return result, true
176 }
177 return nil, false
178}
179
180func isSliceType(v interface{}) bool {
181 if v == nil {

Callers 4

typeCheckMethod · 0.85
jpfMaxFunction · 0.85
jpfMinFunction · 0.85
jpfSortFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…