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

Projects
None yet
4 participants
@b-s-a
Copy link

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Member

commented Feb 18, 2017

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

@bradfitz bradfitz closed this Feb 18, 2017

@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.
You can’t perform that action at this time.