They are distinct indeed. An "if sl == nil ..." will not match an empty slice. It is len(sl) that returns 0 for both nil and empty slices, and range working along the same idea.
playground example: https://goplay.tools/snippet/df0bG6YXfJZ https://goplay.tools/snippet/df0bG6YXf https://goplay.tools/snippet/df0bG6YXfJZ On Thursday, April 11, 2024 at 12:42:21 PM UTC+2 Juliusz Chroboczek wrote: > > I don't know if JSON serialization is deterministic, but I know a couple > > of cases when it is not. > > > If the type or some type inside it has a custom JSON marshaller (method > > MarshalJSON), then if that function's output is not deterministic, the > > whole JSON for the type is not deterministic. > > Obviously. > > > Another common pitfall with JSON: nil vs empty slice. E.g. []string{} is > > encoded as "[]", while []string(nil) is encoded as "null", while they > both > > mean an empty slice in Go > > I'm not sure I follow. I was under the impression that the empty array > and nil are distinct values in Go, even though many functions treat them > the same. > > -- Juliusz > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/9d28bdda-27dd-45a5-9863-b259cad2a088n%40googlegroups.com.