| ▲ | binary132 3 days ago |
| how is a nil map not null? It certainly isn’t a zero-valued map, that would be {}. |
|
| ▲ | atombender 3 days ago | parent | next [-] |
| The zero value of a map is indeed nil in Go: This prints true (https://go.dev/play/p/8dXgo8y2KTh): var m map[string]int
println(m == nil)
|
| |
|
| ▲ | materielle 3 days ago | parent | prev [-] |
| It should be marshaled into {} by default, with a opt-out for special use cases. There’s a simple reason: most JavaScript parsers reject null. At least in the slice case. |
| |
| ▲ | tubthumper8 2 days ago | parent [-] | | Not sure what you mean here by "most JavaScript parser rejects null" - did you mean "JSON parsers"? And why would they reject null, which is a valid JSON value? It's more that when building an API that adheres to a specification, whether formal or informal, if the field is supposed to be a JSON array then it should be a JSON array. Not _sometimes_ a JSON array and _sometimes_ null, but always an array. That way clients consuming the JSON output can write code consuming that array without needing to be overly defensive |
|