title: Passing a string map as an environment variable in Go using Viper
body: <p>For a project I'm working on I'm trying to pass a map of stings as an environment variable using Viper. I tried several approaches to achieve this but with no success. When I read the env variable from code it is empty. This is the code I'm using:</p>
  
  <pre><code>// To configure viper
  viper.SetEnvPrefix("CONFIG")
  viper.AutomaticEnv()
  replacer := strings.NewReplacer(".", "_")
  viper.SetEnvKeyReplacer(replacer)
  
  // To read the configuration value I tried all this variants:
  fmt.Print(viper.GetString("options.values"))
  fmt.Print(viper.GetStringMapString("options.values"))
  fmt.Print(viper.GetStringMap("options.values"))
  </code></pre>
  
  <p>And this is how I'm passing the value:</p>
  
  <p>CONFIG_OPTIONS_VALUES_ROOT="."</p>
  
  <p>I've also tried:</p>
  
  <p>CONFIG_OPTIONS_VALUES="{\"root\": \".\",\"cmd\": \"exec\", \"logging\": \"on\"}"</p>
  
  <p>The way I want to process the value passes in the env variable is:</p>
  
  <pre><code>values := viper.GetStringMapString("options.values")
  for key, val := range values {
      fmt.Printf("Key: %s, Value: %s", key, val)
  }
  </code></pre>
  
  <p>Which I can perfectly do if I write this configuration in a config file and I read it using viper:</p>
  
  <pre><code>options:
          values:
                  root: .
                  cmd: exec
                  logging: on
                  #more values can be added here 
  </code></pre>
  
  <p>Hope someone can point me in the right direction here.</p>