mirror of
https://github.com/spf13/viper
synced 2025-05-11 22:57:21 +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":
|
case "json":
|
||||||
if err := json.Unmarshal(buf.Bytes(), &c); err != nil {
|
type cl []map[string]interface{}
|
||||||
return ConfigParseError{err}
|
|
||||||
|
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":
|
case "hcl":
|
||||||
|
|
Loading…
Add table
Reference in a new issue