encoding icon indicating copy to clipboard operation
encoding copied to clipboard

Decode JSON with type convert from string to integer

Open priyadarshan1995 opened this issue 6 years ago • 3 comments

While using segmentio's json Unmarshaling to unmarshal data to a struct having field *intjson:"Field,string" ` in its definition , I'm getting field as "null" instead of null if its not there in the data.

priyadarshan1995 avatar Jan 28 '20 12:01 priyadarshan1995

Hello @priyadarshan1995, thanks for reporting the issue!

I'll look into the issue a little later today 👍

achille-roussel avatar Jan 28 '20 16:01 achille-roussel

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 avatar Feb 03 '20 16:02 achille-roussel

@achille-roussel Thanks!

priyadarshan1995 avatar Feb 04 '20 05:02 priyadarshan1995