There is such struct:
Programs struct {
ID int `json:"id"`
ShortName string `json:"short_name"`
ProgramPoints float64 `json:"program_points"`
Countries []string `json:"countries"`
}
The column countries is JSON column which contains array of countries ["US","GB"]
Parsing:
stmt, err := db.Query(sql)
err = stmt.Scan(
&program.ID,
&program.ShortName,
&program.ProgramPoints,
&program.Countries)
Has error
unsupported Scan, storing driver.Value type []uint8 into type *[]string
I've found the way how to parse JSON object to struct but not array. Thx in advance for any help
countriesis not exported.json.Marshal(andjson.Unmarshal) don't handle unexported fields. Change the name toCountriesand it should work just fineScanmethod to unmarshal it. The values from SQL are eitherstringor[]byte. You'll need to handle it as JSON in a custom callback, I'll post an answer