github.com/rita33cool1/iot-system-gateway@v0.0.0-20200911033302-e65bde238cc5/docker-engine/api/server/httputils/httputils_write_json.go (about) 1 package httputils // import "github.com/docker/docker/api/server/httputils" 2 3 import ( 4 "encoding/json" 5 "net/http" 6 ) 7 8 // WriteJSON writes the value v to the http response stream as json with standard json encoding. 9 func WriteJSON(w http.ResponseWriter, code int, v interface{}) error { 10 w.Header().Set("Content-Type", "application/json") 11 w.WriteHeader(code) 12 enc := json.NewEncoder(w) 13 enc.SetEscapeHTML(false) 14 return enc.Encode(v) 15 }