spf13 / viper

Go configuration with fangs
MIT License
27.21k stars 2.02k forks source link

Top level JSON Array `ReadInConfig` #91

Open Volox opened 9 years ago

Volox commented 9 years ago

Hi, i have a problem using the ReadInConfig method. I am loading data from a JSON file structured as follows:

[
  {
    "name": "sample1"
  },
  {
    "name": "sample2"
  }
]

When reading it using err = viper.ReadInConfig() i got the following error:

ERROR: 2015/07/03 Error parsing config: json: cannot unmarshal array into Go value of type map[string]interface {}
exit status 1
kzvezdarov commented 9 years ago

That is most likely because right now we assume that the root data structure of a json/yaml configuration is a map, not an array like in the above sample.

Volox commented 9 years ago

Ok, is there a plan for supporting them?

wofr commented 8 years ago

Ran into the same issue today. json: cannot unmarshal array into Go value of type map[string]interface {}

BorisKozo commented 6 years ago

Same issue for me and this is over 1 year old

BorisKozo commented 6 years ago

Can this be supported via viper.GetStringMap("") ?

ankur22 commented 5 years ago

Ran into the same issue here, so i'll have to change the structure of json which isn't a big deal, but it would be nice if arrays could be supported.

sakshamkhanna commented 5 years ago

Is adding support to read from arrays a planned feature? If so, I would like to pick it up

cedws commented 2 years ago

Also happens with a YAML config if the root level is an array:

2022/05/02 09:43:45 error reading config file: While parsing config: yaml: unmarshal errors:
  line 1: cannot unmarshal !!seq into map[string]interface {}
Ingram7 commented 1 year ago

While parsing config: json: cannot unmarshal array into Go value of type map[string]interface {}

zphilin commented 1 year ago

still exist this problem........

shackra commented 5 months ago

who else in 2024?