Skip to content

sendJSON

hc.sendJSON(value, statusCode?)

Available since v2.0.0

Signature:(value: any, statusCode?: number) => Promise<void>

ParameterTypeDescription
valueRequired. Value to JSON-serialize as the response body.
statusCodeOptional. HTTP status (default 200). Must be an integer between 100 and 599.

Same as hc.send, but the body is JSON.stringify(value) and Content-Type is application/json.

Use await — top-level await hc.sendJSON(...) is supported.

Throws when statusCode is invalid or value is not JSON-serializable.

javascript
await hc.sendJSON(
  {
    error: "Something happened.",
  },
  400
);
hc.execution.skipRequest();