I have this simple JSON string where I want user_id to be converted into string when doing json.Unmarshal:
{"user_id": 344, "user_name": "shiki"} I have tried this:
type User struct { Id string `json:"user_id,int"` Username string `json:"user_name"` } func main() { input := `{"user_id": 344, "user_name": "shiki"}` user := User{} err := json.Unmarshal([]byte(input), &user) if err != nil { panic(err) } fmt.Println(user) } But I just get this error:
panic: json: cannot unmarshal number into Go value of type string Playground link: http://play.golang.org/p/mAhKYiPDt0