Navigation Menu

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: please document that float +inf/-inf/nan will cause json.Marshal return error #59627

Closed
bronze1man opened this issue Apr 14, 2023 · 4 comments
Labels
Documentation NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@bronze1man
Copy link
Contributor

What version of Go are you using (go version)?
go version go1.19.2 darwin/amd64

Does this issue reproduce with the latest release?
It does with go playground

What did you do?
Same as #3480

https://play.golang.org/p/K4xwS7iy4MP

What did you expect to see?
Document that float +inf/-inf/nan will cause json.Marshal return error or Not throwing serialization errors on basic numeric data types with valid state.

What did you see instead?
No document of this kind of thing and return json: unsupported value: NaN

Should golang standard library document possible/common error type of a package or a function like windows api document(https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-deletefilew) or linux man (https://linux.die.net/man/3/mmap)?
Code with standard library sometime looks like try and fix again and again without document of possible/common error type.

reference:

@dr2chase
Copy link
Contributor

@rsc @dsnet @mvdan

@dr2chase dr2chase added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 14, 2023
@dsnet
Copy link
Member

dsnet commented Apr 14, 2023

I don't think we can change the behavior, so documenting it seems best.

For the record, as part of #21990, I proposed extending the concept of type-specific format flags to handle non-finite floating point values.

@bronze1man
Copy link
Contributor Author

@dsnet
Agree with you.
If we can not change the behavior, then we should document all the odd behaviors(another one
#20555), and make the caller to decide whether use this library or use another one base on his need.
I do not need to work with float64/float32 and +inf/-inf/nan. So I am ok with current encoding/json.
I just find this problem from view the source code when I am writing another json library with paste and copy .

@gopherbot
Copy link

Change https://go.dev/cl/496142 mentions this issue: encoding/json: document unsupported float values

@dmitshur dmitshur added this to the Go1.21 milestone May 20, 2023
@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels May 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants