WriteJSONResponse
Writes a JSON to the http output stream
def WriteJSONResponse(
resp: http.ResponseWriter,
code: int,
body: interface{}
) - > error
Writes a JSON to the HTTP output stream. This function is used to send a JSON formatted response back to the client.
Parameters
| Name | Type | Description |
|---|---|---|
| resp | http.ResponseWriter | The HTTP response writer to which the JSON response will be written. |
| code | int | The HTTP status code to set for the response (e.g., 200 for OK, 400 for Bad Request). |
| body | interface{} | The data structure to be marshaled into JSON and sent as the response body. |
Returns
| Type | Description |
|---|---|
error | An error if marshaling the body to JSON fails or if writing the string response encounters an issue. |