Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decode JSON with type convert from string to integer #30

Open
priyadarshan1995 opened this issue Jan 28, 2020 · 3 comments
Open

Decode JSON with type convert from string to integer #30

priyadarshan1995 opened this issue Jan 28, 2020 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@priyadarshan1995
Copy link

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.

@achille-roussel achille-roussel self-assigned this Jan 28, 2020
@achille-roussel achille-roussel added the bug Something isn't working label Jan 28, 2020
@achille-roussel
Copy link
Contributor

Hello @priyadarshan1995, thanks for reporting the issue!

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

@achille-roussel
Copy link
Contributor

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.

@priyadarshan1995
Copy link
Author

@achille-roussel Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants