Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
encoding/json: Unmarshal(byte(`null`), &value) does nothing #6724
What steps will reproduce the problem? http://play.golang.org/p/iVsT1IeNkU This code: var s string = "foo" err := Unmarshal(byte(`null`), &s) does not change s, but also does not signal an error. While this does make some sense, it surprised me; I expected either an error or zero value. Error because `null` is not a string, zero value because that's what the logic is elsewhere for null: http://golang.org/pkg/encoding/json/#Unmarshal says "To unmarshal JSON into a pointer, Unmarshal first handles the case of the JSON being the JSON literal null. In that case, Unmarshal sets the pointer to nil. Otherwise, Unmarshal unmarshals the JSON into the value pointed at by the pointer. If the pointer is nil, Unmarshal allocates a new value for it to point to." which means that unmarshaling `null` into a pointer actually changes it, and unmarshaling `null` into a non-pointer doesn't. I feel like the docs need an extra paragraph that talks about null.