Bird
0
0

Identify the error in this nested error JSON snippet:

medium📝 Debug Q6 of 15
Rest API - Error Handling

Identify the error in this nested error JSON snippet:

{
  "errors": {
    "phone": "Invalid",
    "phone": {
      "format": "Wrong",
      "length": "Too short"
    }
  }
}

AThe nested object under 'phone' is invalid JSON
BThe error messages should be numbers, not strings
CDuplicate keys for 'phone' cause the first to be overwritten
DThe 'errors' key must be an array, not an object
Step-by-Step Solution
Solution:
  1. Step 1: Check for duplicate keys in JSON

    JSON objects cannot have duplicate keys; the second 'phone' overwrites the first.
  2. Step 2: Understand impact on error reporting

    This causes the simple string error to be lost, only nested errors remain.
  3. Final Answer:

    Duplicate keys for 'phone' cause the first to be overwritten -> Option C
  4. Quick Check:

    Duplicate JSON keys overwrite earlier ones [OK]
Quick Trick: JSON keys must be unique; duplicates overwrite [OK]
Common Mistakes:
  • Thinking nested objects are invalid JSON
  • Expecting error messages as numbers
  • Assuming 'errors' must be an array

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes