Bird
0
0

A REST API uses 422 Unprocessable Entity for validation errors. How should it handle nested JSON validation errors for a user address field?

hard📝 Application Q9 of 15
Rest API - HTTP Status Codes
A REST API uses 422 Unprocessable Entity for validation errors. How should it handle nested JSON validation errors for a user address field?
AReturn 422 with a JSON error object showing nested keys and messages
BReturn 422 with a single error message ignoring nested details
CReturn 400 Bad Request for nested errors
DReturn 500 Internal Server Error for nested validation issues
Step-by-Step Solution
Solution:
  1. Step 1: Understand nested validation error reporting

    Best practice is to return detailed nested error info so clients know exactly which nested fields failed.
  2. Step 2: Compare with other options

    Ignoring nested details or using 400/500 is less precise and not recommended for validation errors.
  3. Final Answer:

    Return 422 with a JSON error object showing nested keys and messages -> Option A
  4. Quick Check:

    Nested validation errors need detailed JSON in 422 response [OK]
Quick Trick: Use nested JSON error details with 422 for complex validation [OK]
Common Mistakes:
MISTAKES
  • Returning generic error messages for nested fields
  • Using 400 or 500 instead of 422 for validation
  • Not including nested keys in error response

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes