Bird
Raised Fist0

Which of the following is the correct JSON structure for a consistent error response in a REST API?

easy📝 Syntax Q3 of Q15
Rest API - Error Handling
Which of the following is the correct JSON structure for a consistent error response in a REST API?
A{"error": {"code": "NOT_FOUND", "message": "Resource not found"}}
B{"error_code": "NOT_FOUND", "error_message": "Resource not found"}
C{"code": "NOT_FOUND", "msg": "Resource not found"}
D{"error": "NOT_FOUND", "message": "Resource not found"}
Step-by-Step Solution
Solution:
  1. Step 1: Check for nested error object

    Consistent error responses usually wrap details inside an "error" object.
  2. Step 2: Verify keys and structure

    {"error": {"code": "NOT_FOUND", "message": "Resource not found"}} uses "code" and "message" keys inside "error", which is a common standard.
  3. Final Answer:

    {"error": {"code": "NOT_FOUND", "message": "Resource not found"}} -> Option A
  4. Quick Check:

    Correct JSON error format = {"error": {"code": "NOT_FOUND", "message": "Resource not found"}} [OK]
Quick Trick: Use nested 'error' object with 'code' and 'message' keys [OK]
Common Mistakes:
MISTAKES
  • Using flat keys without nesting
  • Using inconsistent key names like 'msg'
  • Missing quotes or braces in JSON

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes