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: support decoding to []int from []string by applying tag ,string #15624

localvar opened this issue May 10, 2016 · 8 comments
FeatureRequest NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.


Copy link

localvar commented May 10, 2016

Please answer these questions before submitting your issue. Thanks!

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

  2. What operating system and processor architecture are you using (go env)?
    set GOARCH=amd64
    set GOBIN=
    set GOEXE=.exe
    set GOHOSTARCH=amd64
    set GOHOSTOS=windows
    set GOOS=windows
    set GOPATH=D:\litead\oxygen
    set GORACE=
    set GOROOT=C:\go
    set GOTOOLDIR=C:\go\pkg\tool\windows_amd64
    set CC=gcc
    set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
    set CXX=g++
    set CGO_ENABLED=1

  3. What did you do?
    If possible, provide a recipe for reproducing the error.
    A complete runnable program is good.
    A link on is best.

  4. What did you expect to see?
    decode the int64 slice successfully

  5. What did you see instead?
    an error:

    json: cannot unmarshal string into Go value of type int64

according to the documentation, the behavior is correct, but this makes it hard to decode an int64 slice (although there are workarounds). It will be good if 'string' tag could also be applied to slices.

@bradfitz bradfitz added this to the Unplanned milestone May 10, 2016
Copy link

jheiselman commented Aug 12, 2016

I believe that this may be affecting the ability to parse JSON responses from the Slack messaging platform. Recently, my go-based Slack bot has been failing to parse the initial response after authenticating, but nothing appears to have changed in the server response and the response does successfully pass jslint.

@odeke-em odeke-em changed the title encoding/json: unable to decode int64 slice encoding/json: support decoding to []int from []string by applying tag ,string Aug 19, 2016
@odeke-em odeke-em self-assigned this Aug 20, 2016
Copy link

odeke-em commented Aug 20, 2016

I've mailed CL

Copy link

gopherbot commented Aug 20, 2016

CL mentions this issue.

Copy link

localvar commented Aug 22, 2016

@odeke-em , Thanks for the CL.
If I'm reading the code correct, tags like json:"i64" is used in the fix, this seems not consistent with other tags, for example when we want an int64, we use: json:",string"

Copy link

odeke-em commented Aug 22, 2016

@localvar thanks for taking a look at it, let's put comments on the CL there though.
But anyways, am using "i64" as the key and not as the auxilliary tag; it is so that the respective Go struct attribute will receive the unmarshaled data of json data key "i64", so

{"i64": ["12", "33", "999"]}

and Go code

type receiver struct {
   I64 []uint64 `json:"i64,string"`

the data in "i64" will be unmarshaled and assigned to I64.
It could have been

"keys" -> I64 []int `json:"keys,string"`

But let's move discussion to the CL itself to avoid noise here but also to ensure that we don't miss out on concerns that should be addressed in the CL.

@bradfitz bradfitz added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label May 24, 2017
@bradfitz bradfitz modified the milestones: Go1.9Maybe, Unplanned May 24, 2017
Copy link

bradfitz commented May 24, 2017

@rsc, can I get a JSON decision here?

@bradfitz bradfitz modified the milestones: Go1.9Maybe, Go1.10 Jul 20, 2017
@rsc rsc modified the milestones: Go1.10, Go1.11 Nov 22, 2017
@ianlancetaylor ianlancetaylor modified the milestones: Go1.11, Go1.12 Jun 29, 2018
Copy link

rskumar commented Jul 25, 2018

This is like fixing someone's wrong JSON by using some magic in tags. This shouldn't be language or core libs part.

Rather, if we can attach a field processor func, where we get raw bytes and json field tag and do our work explicitly and then return expected type value or error. The returned post-processed value will then be assigned to that field by JSON unmarshaller.

Copy link

titpetric commented Oct 26, 2018

Hey, is there anything I could do to push this along? I have a few use cases where I need to deal with encoding a slice of uint64's, and am having issues inter-operating with javascript in the browser. I wouldn't like to resort to a typed uint64 and custom (un)marshallers to resolve this encoding issue, if there's a chance we can push this into go 1.12? I see there are a only a couple of code review comments open, and the concerns shouldn't be hard to resolve. Thoughts?

@rsc rsc modified the milestones: Go1.12, Go1.13 Nov 14, 2018
darh added a commit to crusttech/crust-server that referenced this issue Apr 27, 2019
Due to golang's inability do decode uint64 slice from string slice, we're expecting
string input for members (for now): golang/go#15624
@andybons andybons removed this from the Go1.13 milestone Jul 8, 2019
@seankhliao seankhliao added this to the Unplanned milestone Aug 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
FeatureRequest NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
None yet

No branches or pull requests