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

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


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.

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

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

Copy link

vcabbage commented Feb 18, 2017

You can already handle this by implementing the json.Unmarshaler interface or using the json.Number type. Example:

Copy link

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.
None yet

No branches or pull requests

4 participants