I have a struct:type Customer struct {Id int64Name sql.NullString}
Is there some clever way to get only the needed data? NULL values can be empty strings:[{"Id":1,"Name":"John"}, {"Id":2,"Name":""}]
Hello!I'm trying to handle a trivial case but sql.NullString makes it rather complicated.
I have a struct:type Customer struct {Id int64Name sql.NullString}
which is loaded from a database like this:func (c *Customer) fetch(rows *sql.Rows) error {return rows.Scan(&c.Id, &c.Name)}Customer.Name (supposedly) has to be a sql.NullString because the database has NULL values in that fields which caused error if Customer.Name was a string type.However, json.Marshal(customer) produces some unwanted JSON with both String and Valid fields from sql.NullString:[{"Id":1,"Name":{"String":"John","Valid":true}}]
Is there some clever way to get only the needed data? NULL values can be empty strings:[{"Id":1,"Name":"John"}, {"Id":2,"Name":""}]
-Nikolai