Validation error JSON response example

Last updated 2026-05-20

Example JSON

POST /users/add with a bad payload returns this shape.

{
  "message": "Validation failed",
  "code": "validation_failed",
  "errors": {
    "email": [
      "Email is required",
      "Email must be valid"
    ],
    "password": [
      "Password must be at least 8 characters"
    ],
    "age": [
      "Age must be a positive integer"
    ]
  }
}

Request examples

const res = await fetch('https://jsonexamples.com/users/add', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ email: '', password: '123', age: -1 })
});
if (!res.ok) {
  const { errors } = await res.json();
  console.error(errors);
}

Try the live endpoint

Click below to call /http/422/Validation+failed from your browser.

GET/http/422/Validation+failed
{
  "hint": "Click 'Run' to call the live endpoint"
}

Common variations

RFC 7807 problem+json

Equivalent error in the IETF problem-details format.

{
  "type": "https://jsonexamples.com/errors/validation-failed",
  "title": "Validation failed",
  "status": 422,
  "detail": "Three fields failed validation.",
  "instance": "/users/add",
  "errors": [
    {
      "field": "email",
      "message": "Email is required"
    },
    {
      "field": "password",
      "message": "Password must be at least 8 characters"
    }
  ]
}

Convert this JSON

Generated starting points for TypeScript, JSON Schema, and Zod. Refine before shipping to production.

export interface ValidationError {
  "message": string;
  "code": string;
  "errors": {
    "email": string[];
    "password": string[];
    "age": string[];
  };
}
Back to examples

Related examples