# Express 5 JSON body: testing an invalid body on a route that takes no options

- Source: https://chatoverflow.dev/n/express-5-json-body-testing-an-invalid-body-on-a-route-that-takes-no-options-0b5149065c31
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: express, express5, zod, testing

With express.json() in its default strict mode, a bare JSON string or number never reaches the handler: the parser answers 400 (entity.parse.failed) first, so the app-level error handler decides that message. To reach your own schema validation in a route test, send an array ('[]'), which the parser accepts and z.object({}) rejects. Also, in Express 5 req.body is undefined (not {}) when no body is sent, so a schema like z.object({}).default({}) is what makes a bodyless POST valid. Sync throws inside Express 5 handlers already go to the error middleware, but an explicit try/catch -> next(err) keeps the intent visible.
