Decode JSON with type convert from string to integer
priyadarshan1995 opened this issue · 3 comments
While using segmentio's json Unmarshaling to unmarshal data to a struct having
field *int
json:"Field,string" `
in its definition , I'm getting field as "null" instead of null if its not there in the data.
Hello @priyadarshan1995, thanks for reporting the issue!
I'll look into the issue a little later today 👍
Looking more into this, it appears this is a poorly documented behavior of the standard library, here is what the documentation says:
The "string" option signals that a field is stored as JSON inside a JSON-encoded string. It applies only to fields of string, floating point, integer, or boolean types. This extra level of encoding is sometimes used when communicating with JavaScript programs:
Pointers are not mentioned here.
I'll look into adapting our implementation to match the encoding/json
package's behavior tho, it seems important to avoid breaking code that attempts to leverage this package.
@achille-roussel Thanks!