Valuer and Scanner
type JSON map[string]any
func (j JSON) Value() (driver.Value, error) {
return json.Marshal(j)
}
func (j *JSON) Scan(src any) error {
switch v := src.(type) {
case []byte:
return json.Unmarshal(v, j)
case string:
return json.Unmarshal([]byte(v), j)
case nil:
*j = nil; return nil
}
return fmt.Errorf("cannot scan %T into JSON", src)
}