How do you marshal a sql.NullString such that the output is flattened to give just the value in go?
问题 Given a go struct type Company struct { ID int `json:"id"` Abn sql.NullString `json:"abn,string"` } when marshalled with something like this company := &Company{} company.ID = 68 company.Abn = "SomeABN" result, err := json.Marshal(company) the result is { "id": "68", "abn": { "String": "SomeABN", "Valid": true } } The result desired is { "id": "68", "abn": "SomeABN" } I've tried explicitly stating that Abn is a string. Abn sql.NullString `json:"abn,string"` which did not change the result.