MCPcopy Create free account
hub / github.com/cortexlabs/cortex / JSONMarshallable

Function JSONMarshallable

pkg/lib/cast/interface.go:698–729  ·  view source on GitHub ↗

Recursively casts interface->interface maps to string->interface maps

(in interface{})

Source from the content-addressed store, hash-verified

696
697// Recursively casts interface->interface maps to string->interface maps
698func JSONMarshallable(in interface{}) (interface{}, bool) {
699 if in == nil {
700 return nil, true
701 }
702
703 if inMap, ok := InterfaceToInterfaceInterfaceMap(in); ok {
704 out := map[string]interface{}{}
705 for key, value := range inMap {
706 castedKey, ok := key.(string)
707 if !ok {
708 return nil, false
709 }
710 castedValue, ok := JSONMarshallable(value)
711 if !ok {
712 return nil, false
713 }
714 out[castedKey] = castedValue
715 }
716 return out, true
717 } else if inSlice, ok := InterfaceToInterfaceSlice(in); ok {
718 out := make([]interface{}, 0, len(inSlice))
719 for _, inValue := range inSlice {
720 castedInValue, ok := JSONMarshallable(inValue)
721 if !ok {
722 return nil, false
723 }
724 out = append(out, castedInValue)
725 }
726 return out, true
727 }
728 return in, true
729}
730
731func InterfaceToStrStrMap(in interface{}) (map[string]string, bool) {
732 if in == nil {

Callers 2

ExtractAPIConfigsFunction · 0.92
TestJSONMarshallableFunction · 0.85

Calls 2

Tested by 1

TestJSONMarshallableFunction · 0.68