Closed mayeter closed 10 months ago
This is supported, please read the documentation and examples before creating the issue
look up omitempty
tag here:
https://pkg.go.dev/github.com/jszwec/csvutil#Decoder.Decode
and here
https://github.com/jszwec/csvutil?tab=readme-ov-file#examples_unmarshal
Thank you very much, this solves my problem. Interesting that I never noticed that tag, I actually reviewed it a couple times.
Hello, I have a CSV file which has some optional fields. Unmarshal method gives me this error if any non-string field is empty. It works perfectly when all fields are filled or empty fields are corresponding to a string value.
Here is what my csv file looks like:
And my go struct:
It also gives non-existinf column numbers in the error:
csvutil: cannot unmarshal "" into Go value of type int: field "ttl" line 2 column 39
or
csvutil: cannot unmarshal "" into Go value of type bool: field "proxy_enabled" line 2 column 42
I can work around of this by converting my optional fields' types to string and convert them with
strconv
, but it would be nice if Unmarshall would handle it.Thanks, great work by the way