I want to able to send null
to the browser as JSON, if I do this:
json.NewEncoder(w).Encode(nil)
then null
will be received by the browser. However in this context:
var nearby map[string]Nearby
// ...
func GetOne(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
item := nearby[params["id"]] // item could be nil?
json.NewEncoder(w).Encode(item)
}
if nothing exists in the map, then {}
will be received by the browser instead of null
...is there some way I can send null
if the key is not in the map?