title: How to unmarshal a json string with a hyphen in key to a struct?
body: <p>I have following code which is ok, it will print <code>Bob</code>:</p>
  
  <pre><code>package main
  
  import (
      "encoding/json"
      "fmt"
  )
  
  type User struct {
      UserName string  // line2
      Age  int
  }
  
  func main() {
      var u User
      str := `{"userName":"Bob", "age": 20}` // line1
      json.Unmarshal([]byte(str), &amp;u)
      fmt.Println(u.UserName)
  }
  </code></pre>
  
  <p>Unfortunately, in real case, the json string in <code>line1</code> is next, which you could see there is a hyphen(<code>-</code>) in the key.</p>
  
  <pre><code>str := `{"user-Name":"Bob", "age": 20}`
  </code></pre>
  
  <p>And as you all know, to automatically unmarshal the json string, we have to define a member in struct which is the same name of the key in json string, of course need to make it upper case. So I tried to change <code>line2</code> to <code>User-Name string</code>, but <code>-</code> is not valid in <code>go</code> variable name. What should I do?</p>