You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: response.go
    path of file: ./repos/bud/framework/controller/controllerrt/response
    
    the code of the file until where you have to start completion: package response

import (
	"encoding/json"
	"fmt"
	"net/http"
	"path"

	"github.com/livebud/bud/framework/controller/controllerrt/request"
)

// Format returns different responses depending on the Accepts request header
// TODO: tighten up the types. Maybe HTML(w, r) & JSON(w, r) interfaces
type
    
func (res *Response) JSON(props interface{}) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		// Attach all preset headers
		header := w.Header()
		for key, value := range res.headers {
			header.Set(key, value)
		}
		// Override any existing content types
		header.Set("Content-Type", "application/json")
		// Marshal the JSON response
		result, err := json.Marshal(props)
		if err != nil {
			w.WriteHeader(500)
			// TODO: standardize this
			w.Write([]byte(fmt.Sprintf(`{"error":{"message":%q}}`, err.Error())))
			return
		}
		// Default status is 200 OK
		if res.status == 0 {
			res.status = 200
		}
		// Write the response
		w.WriteHeader(res.status)
		w.Write(result)
	})
}