github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/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 }