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

Comments

Projects
None yet
3 participants
@bradfitz

This comment has been minimized.

Copy link
Member

commented Apr 10, 2015

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.

@bradfitz bradfitz closed this Apr 10, 2015

@vincepri

This comment has been minimized.

Copy link
Author

commented Apr 10, 2015

@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

This comment has been minimized.

Copy link
Member

commented Apr 10, 2015

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

This comment has been minimized.

Copy link
Author

commented Apr 10, 2015

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.
You can’t perform that action at this time.