How can I convert []interface to []strings or just as a joined single string with all elements in []interface ? Below is the screenshot showing exact value of "scope" which of type []interface with length of 2. In below code, where case is "slice" Currently i am doing this using reflect but this is not looking good. Wondering there should be some good way to join a slice\array of interface elements.
I also did try using json unmarshall like this "json.Unmarshal([]byte(jwtResp),&mymap)" but having trouble with type issues in converting jwt.MapClaims to byte[]
parsedkey, _ := jwt.ParseRSAPublicKeyFromPEM([]byte(key)) parsedToken, jwtErr := jwt.Parse(bearerToken, func(token *jwt.Token) (interface{}, error) { return parsedkey, nil }) jwtValues = make(map[string]string) // we dont know which data types we are dealing with here, so using swtich case based on value data type jwtResp := parsedToken.Claims.(jwt.MapClaims) for k, v := range jwtResp { switch reflect.TypeOf(v).Kind() { case reflect.Slice: fmt.Println("tp is : ", reflect.TypeOf(v)) // this is []interface{} fmt.Println("type is : ", reflect.TypeOf(v).Kind()) // this is slice s := reflect.ValueOf(v) for i := 0; i < s.Len(); i++ { jwtValues[k] += s.Index(i).Interface().(string) jwtValues[k] += "|" } case reflect.String: jwtValues[k] = v.(string) default: fmt.Println("unknown datatype") } } 