# HttpProtect.jsonMiddleware() method · @imqueue/http-protect

Source: https://imqueue.org/api/http-protect/latest/http-protect.httpprotect.jsonmiddleware/
Published: 2026-08-01
Author: @imqueue maintainers (https://github.com/imqueue)
Package: @imqueue/http-protect 3.0.1 — generated reference, not hand-written

A middleware that rejects with a JSON error body.

**Signature:**

```typescript
jsonMiddleware(): (req: Request, res: Response, next: NextFunction) => Promise<void>;
```
**Returns:**

(req: Request, res: [Response](https://imqueue.org/api/http-protect/latest/http-protect.response/), next: [NextFunction](https://imqueue.org/api/http-protect/latest/http-protect.nextfunction/)) => Promise<void>

An async middleware to hand to `app.use()`.

## Remarks

The usual choice for an API. The body is `{"error":{"type":"HTTP","code":429,"message":"Too Many Requests"}}`, with 418 and `I'm a teapot` for a ban. `Content-Type` is set as described in [HttpProtect.textMiddleware()](https://imqueue.org/api/http-protect/latest/http-protect.httpprotect.textmiddleware/).

## Example


```typescript
const protect = new HttpProtect({ redis: existingClient });

app.use(protect.jsonMiddleware());
```

