package model import ( "database/sql/driver" "encoding/json" "errors" ) type JSONB map[string]interface{} func (a JSONB) Value() (driver.Value, error) { return json.Marshal(a) } func (a *JSONB) Scan(value interface{}) error { b, ok := value.([]byte) if !ok { return errors.New("type assertion to []byte failed") } return json.Unmarshal(b, &a) } // JSONBS Interface for JSONB Field of yourTableName Table type JSONBS []interface{} func (a JSONBS) Value() (driver.Value, error) { return json.Marshal(a) } func (a *JSONBS) Scan(value interface{}) error { b, ok := value.([]byte) if !ok { return errors.New("type assertion to []byte failed") } return json.Unmarshal(b, &a) }