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

encoding/json: parsing comma in value to []byte field fails #24428

Closed
tehsphinx opened this issue Mar 16, 2018 · 2 comments
Closed

encoding/json: parsing comma in value to []byte field fails #24428

tehsphinx opened this issue Mar 16, 2018 · 2 comments

Comments

@tehsphinx
Copy link

tehsphinx commented Mar 16, 2018

What version of Go are you using (go version)?

go version go1.10 darwin/amd64

What did you do?

Parsing a json with a comma in the value will fail if the target variable is []byte and not string:
https://play.golang.org/p/5dDCW9mwDv8

What did you expect to see?

Unmarshalled json object

What did you see instead?

Error:
illegal base64 data at input byte 4

@tehsphinx
Copy link
Author

Or is this behavior intended?

@tehsphinx
Copy link
Author

tehsphinx commented Mar 16, 2018

It is intended.

Explanation for others looking at this: if target field is of type []byte json library expects data to be base64 encoded. It data is not base64 encoded use a field of type string as target on unmarshalling.

@golang golang locked and limited conversation to collaborators Mar 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants