func handler(w http.ResponseWriter, r *http.Request) { w.Write([]byte("Hello, world!")) }
type Person struct { Name string `json:"name"` Email string `json:"email"` } func handler(w http.ResponseWriter, r *http.Request) { person := Person{"John Doe", "[email protected]"} jsonResponse, _ := json.Marshal(person) w.Header().Set("Content-Type", "application/json") w.Write(jsonResponse) }In this example, we define a Person struct and a handler function which returns a JSON response. We use the json.Marshal() method to convert the Person struct to JSON data, and then set the Content-Type header to "application/json" before writing the JSON response to the response stream. Package Library: "net/http"