diff --git a/viper.go b/viper.go index 3517fc7..1d3c7f6 100644 --- a/viper.go +++ b/viper.go @@ -424,7 +424,11 @@ func (v *Viper) searchMap(source map[string]interface{}, path []string) interfac // if the type of `next` is the same as the type being asserted return v.searchMap(next.(map[string]interface{}), path[1:]) default: - return next + if len(path) == 1 { + return next + } + // got a value but nested key expected, return "nil" for not found + return nil } } else { return nil