Flatten: Fix keys

This commit is contained in:
Eric Lippmann 2021-04-23 17:45:29 +02:00
parent 52e5eb774e
commit e71833defb

View file

@ -13,13 +13,11 @@ func Flatten(value interface{}, prefix string) map[string]interface{} {
switch value := value.(type) {
case map[string]interface{}:
for k, v := range value {
key += "." + k
flatten(key, v)
flatten(key+"."+k, v)
}
case []interface{}:
for i, v := range value {
key += "[" + strconv.Itoa(i) + "]"
flatten(key, v)
flatten(key+"["+strconv.Itoa(i)+"]", v)
}
default:
flattened[key] = value