package ingest import ( "fmt" "io" "github.com/go-json-experiment/json/jsontext" ) // NullableString is a string that decodes JSON null as the empty string. type NullableString string func (n *NullableString) UnmarshalJSONFrom(d *jsontext.Decoder) error { t, err := d.ReadToken() switch err { case nil: // do nothing case io.EOF: return io.ErrUnexpectedEOF default: return err } switch t.Kind() { case 'n': *n = "" case '"': *n = NullableString(t.String()) default: return fmt.Errorf("invalid token for nullable string %q", t.String()) } return nil }