mirror of
https://github.com/spf13/viper
synced 2025-05-11 06:37:27 +00:00
Fix: Top level JSON Array ReadInConfig
This commit is contained in:
parent
82c2ddf493
commit
8a2e0cad73
1 changed files with 13 additions and 2 deletions
15
viper.go
15
viper.go
|
@ -1528,8 +1528,19 @@ func (v *Viper) unmarshalReader(in io.Reader, c map[string]interface{}) error {
|
|||
}
|
||||
|
||||
case "json":
|
||||
if err := json.Unmarshal(buf.Bytes(), &c); err != nil {
|
||||
return ConfigParseError{err}
|
||||
type cl []map[string]interface{}
|
||||
|
||||
err := json.Unmarshal(buf.Bytes(), &c)
|
||||
if err != nil {
|
||||
cc := make(cl, 0)
|
||||
if err := json.Unmarshal(buf.Bytes(), &cc); err != nil {
|
||||
return ConfigParseError{err}
|
||||
}
|
||||
for _, item := range cc {
|
||||
for k, v := range item {
|
||||
c[k] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
case "hcl":
|
||||
|
|
Loading…
Add table
Reference in a new issue