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: Unmarshal: slice handling underspecified? #8837

masiulaniec opened this issue Sep 29, 2014 · 1 comment

encoding/json: Unmarshal: slice handling underspecified? #8837

masiulaniec opened this issue Sep 29, 2014 · 1 comment


Copy link

In the below code (from, it appears impossible to
predict program's output based solely on documentation of package encoding/json.

    list := []int{-1}
    err := json.Unmarshal([]byte("[1]"), &list)
    if err != nil 
    log.Printf("%+v", list)

I can think of the following likely outcomes:

  [-1, 1]

Package encoding/json chooses [1] but I cannot seem to find a sentence that guarantees

In contrast, relevant quote from package encoding/xml: "Unmarshal maps an XML
element to a slice by extending the length of the slice and mapping the element to the
newly created value."
Copy link

Comment 1:

Labels changed: added repo-main, release-go1.5, documentation.

@bradfitz bradfitz modified the milestone: Go1.5 Dec 16, 2014
@rsc rsc removed the repo-main label Apr 14, 2015
@rsc rsc closed this as completed in 749b391 Jul 15, 2015
@golang golang locked and limited conversation to collaborators Jul 18, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet

No branches or pull requests

5 participants