4xx Client ErrorCommonly usedRFC 9110
422Unprocessable Entity
Request is well-formed but contains semantic errors.
What it means
The server understands the content type and the request is syntactically correct, but was unable to process the contained instructions. Use for semantic validation errors — the JSON is valid but the data itself is invalid.
When to use it
- ✓JSON is valid but field values are semantically wrong
- ✓Business rule violations (start date after end date)
- ✓Field values fail domain validation
- ✓Referenced resource does not exist
Common causes
- →Valid JSON but invalid field values
- →Password confirmation does not match
- →Date range is invalid
Code Examples
Express — semantic validation
javascript
app.post('/events', (req, res) => {
const { startDate, endDate } = req.body;
// JSON is valid, but dates make no sense
if (new Date(startDate) >= new Date(endDate)) {
return res.status(422).json({
error: 'Unprocessable Entity',
message: 'startDate must be before endDate',
});
}
// ...
});