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: Slice created using reflect.MakeSlice() treated as interface{} #7846

gopherbot opened this issue Apr 23, 2014 · 2 comments


Copy link

by emanuelpalm:

go version 1.2 linux/amd64

What steps reproduce the problem?
If possible, include a link to a program on

What happened?

Basically some slices are treated as of type interface{} when used with json.Unmarshal,
even when they should have enough type information to be treated as of being of some
specific type.

This deals with a true corner case I believe few would be interested in, and it might
even be some design decision made to simplify the implementation of
json.Unmarshal/json.Decode/etc. A good defense of the behavior observed would be
regarded as resolving the issue.

Thank you for making Go great!
Copy link

Comment 1:

In the cases whose behaviour you want to be different, you are passing in a pointer to
an interface{}.  The encoding/json docs describe how JSON is unmarshaled into an
interface value, and that is what you are seeing.  So this is behaving correctly
according to the package docs.
I agree that this makes it hard to decode into a slice created by reflect.MakeSlice.  I
think you'll have to walk the map and assign to the slice using the reflect methods.  At
least, I don't immediately see another way to do it.

Status changed to WorkingAsIntended.

Copy link

Comment 2 by emanuelpalm:

Alright. Thank you for your time.
By the way, I would like to see some decoder/encoder for transforming to and from struct
<-> map[string]interface{} in the standard lib. That would have helped me out.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet

No branches or pull requests

2 participants