github.com/hms58/moby@v1.13.1/api/server/httputils/httputils_write_json.go (about) 1 // +build go1.7 2 3 package httputils 4 5 import ( 6 "encoding/json" 7 "net/http" 8 ) 9 10 // WriteJSON writes the value v to the http response stream as json with standard json encoding. 11 func WriteJSON(w http.ResponseWriter, code int, v interface{}) error { 12 w.Header().Set("Content-Type", "application/json") 13 w.WriteHeader(code) 14 enc := json.NewEncoder(w) 15 enc.SetEscapeHTML(false) 16 return enc.Encode(v) 17 }