github.com/docker/docker@v299999999.0.0-20200612211812-aaf470eca7b5+incompatible/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  }