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

Proposal: encoding/json: add new tag for numbers to be string or number literals for unmarshalling #19175

Closed
b-s-a opened this issue Feb 18, 2017 · 2 comments

Comments

@b-s-a
Copy link

b-s-a commented Feb 18, 2017

Current implementation of json decoder (1.7) requires numbers be integers or strings only if string tag specified. Most web oriented languages (php for example) has no difference between types, so json produced by them can contain integers/floats/booleans as strings.
I suggest to create new tag which permits numbers as strings and ints at same time.
Example:

struct {
    X int `json:"x,maystring"`
}

Can be unmarshalled from {"x":"1234"} and {"x":1234}

@vcabbage
Copy link
Member

vcabbage commented Feb 18, 2017

You can already handle this by implementing the json.Unmarshaler interface or using the json.Number type. Example: https://play.golang.org/p/HGXCF0Bp1X

@bradfitz
Copy link
Contributor

Closing since solutions already exist, and the json package is increasingly frozen for changes.

@golang golang locked and limited conversation to collaborators Feb 18, 2018
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

4 participants