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 of "null" string into map will panic after assignment #10411

Closed
vincepri opened this issue Apr 10, 2015 · 4 comments
Closed

Comments

@vincepri
Copy link

https://play.golang.org/p/6GgCp-aY4Y

@bradfitz
Copy link
Contributor

This is working as intended. You're telling it to turn &m into null, and it is, and then you're assigning to a nil map.

Unmarshal will return an error if you try to unmarshal an integer or boolean, but null and a JSON object can both unmarshal into a map.

@vincepri
Copy link
Author

@bradfitz OK so I guess if that's the intended behavior, why I can still read from the map and it doesn't panic?

@bradfitz
Copy link
Contributor

Because that's how the Go language works:

http://golang.org/ref/spec#Map_types

It says:

A nil map is equivalent to an empty map except that no elements may be added.

@vincepri
Copy link
Author

Oh okay good to know :) Thanks Brad.

On Friday, April 10, 2015, Brad Fitzpatrick notifications@github.com
wrote:

Because that's how the Go language works:

http://golang.org/ref/spec#Map_types

It says A nil map is equivalent to an empty map except that no elements
may be added..


Reply to this email directly or view it on GitHub
#10411 (comment).

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

No branches or pull requests

3 participants