Comment on A new experimental Go API for JSONparentComments−int_19h1yIt is different from nil, but then again a nil map in Go behaves like an empty map when reading from it. If you consider serialization to be "reading", therefore, it makes sense to interpret it accordingly.−leononame1yThat is not true, though. Reading from a nil map panics, and reading from an empty map does not.−int_19h1yIt doesn't. E.g. this prints 0:var m map[string]int = nil fmt.Println(m["foo"])The language spec is also pretty clear on this; https://go.dev/ref/spec#Map_types:A nil map is equivalent to an empty map except that no elements may be added.
Comments
It is different from nil, but then again a nil map in Go behaves like an empty map when reading from it. If you consider serialization to be "reading", therefore, it makes sense to interpret it accordingly.
That is not true, though. Reading from a nil map panics, and reading from an empty map does not.
It doesn't. E.g. this prints 0:
var m map[string]int = nil fmt.Println(m["foo"])
The language spec is also pretty clear on this; https://go.dev/ref/spec#Map_types: