says i have next json
{
name: "John",
birth_date: "1996-10-07"
}
and I want to decode it into the following structure
type Person struct {
Name string `json:"name"`
BirthDate time.Time `json:"birth_date"`
}
like this
person := Person{}
decoder := json.NewDecoder(req.Body);
if err := decoder.Decode(&person); err != nil {
log.Println(err)
}
which gives me an error parsing time ""1996-10-07"" as ""2006-01-02T15:04:05Z07:00"": cannot parse """ as "T"
if I manually disassembled it, I would do it like
t, err := time.Parse("2006-01-02", "1996-10-07")
but when the time value is from json string , how can I get the decoder to parse it in the above format?
source
share