0
0
Rest APIprogramming~20 mins

Validation error details in Rest API - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Validation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this JSON validation error response?
Consider a REST API that validates user input and returns this JSON error response when the 'email' field is missing. What is the output shown to the client?
Rest API
{
  "errors": {
    "email": ["This field is required."]
  },
  "message": "Validation failed"
}
A{"message":"Validation failed","fields":{"email":"required"}}
B{"error":"email is missing","status":400}
C{"errors":{"email":["This field is required."]},"message":"Validation failed"}
D{"status":"error","details":"email missing"}
Attempts:
2 left
💡 Hint
Look for the exact JSON structure that matches the validation error format.
Predict Output
intermediate
1:30remaining
What error message does this API return for invalid password length?
An API validates a password field and returns this JSON error response if the password is too short. What is the exact error message for the password field?
Rest API
{
  "errors": {
    "password": ["Password must be at least 8 characters."]
  },
  "message": "Validation failed"
}
APassword must be at least 8 characters.
BPassword is too short.
CPassword length invalid.
DPassword must contain letters and numbers.
Attempts:
2 left
💡 Hint
Check the exact string inside the password error array.
Predict Output
advanced
2:30remaining
What is the output when multiple fields fail validation?
An API returns this JSON when both 'username' and 'email' fields fail validation. What is the exact JSON output?
Rest API
{
  "errors": {
    "username": ["Username already taken."],
    "email": ["Invalid email format."]
  },
  "message": "Validation failed"
}
A{"error":"Multiple validation errors","fields":{"username":"taken","email":"invalid"}}
B{"errors":{"username":["Username already taken."],"email":["Invalid email format."]},"message":"Validation failed"}
C{"message":"Validation failed","errors":["Username already taken.","Invalid email format."]}
D{"errors":{"username":"Username already taken.","email":"Invalid email format."},"message":"Validation failed"}
Attempts:
2 left
💡 Hint
Look for the JSON where errors are arrays per field.
Predict Output
advanced
1:30remaining
What error does this invalid JSON validation response cause?
This API response is missing a colon after 'errors'. What error will a JSON parser raise?
Rest API
{
  "errors" {
    "email": ["Required field missing."]
  },
  "message": "Validation failed"
}
AJSONDecodeError: Expecting ':' delimiter
BKeyError: 'errors'
CTypeError: string indices must be integers
DNo error, valid JSON
Attempts:
2 left
💡 Hint
Check the syntax near the 'errors' key.
🧠 Conceptual
expert
3:00remaining
Which option correctly describes the structure of detailed validation error responses in REST APIs?
In REST API design, detailed validation error responses typically include which of the following structures?
AA flat list of error strings without field association.
BA single error string summarizing all validation issues.
CAn array of objects each containing a 'code' and 'description' but no field names.
DAn object with a 'message' string and an 'errors' object mapping field names to arrays of error messages.
Attempts:
2 left
💡 Hint
Think about how clients identify which fields failed validation.