Bird
Raised Fist0

Which of the following is the correct JSON format for a human-readable error message in a REST API response?

easy📝 Syntax Q12 of Q15
Rest API - Error Handling

Which of the following is the correct JSON format for a human-readable error message in a REST API response?

{
  "error": {
    "code": 404,
    "message": "Resource not found"
  }
}
A{ error: 404, message: 'Not found' }
B{ "error": { "code": 404, "message": "Resource not found" } }
C{ "code": 404, "msg": "Not found" }
D{ error_code: 404, error_message: 'Resource missing' }
Step-by-Step Solution
Solution:
  1. Step 1: Check JSON syntax correctness

    Valid JSON requires double quotes around keys and string values.
  2. Step 2: Match the expected structure

    The error object should contain code and message keys with clear names.
  3. Final Answer:

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

    Valid JSON with clear keys = { "error": { "code": 404, "message": "Resource not found" } } [OK]
Quick Trick: Look for double quotes and clear key names in JSON [OK]
Common Mistakes:
MISTAKES
  • Using single quotes instead of double quotes in JSON
  • Missing nested error object structure
  • Using incorrect key names like 'msg' or 'error_code'

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes