Bird
0
0

You want to return validation error details for a nested JSON object with fields 'user.name' and 'user.age'. Which JSON structure correctly represents errors for these nested fields?

hard📝 Application Q8 of 15
Rest API - Error Handling
You want to return validation error details for a nested JSON object with fields 'user.name' and 'user.age'. Which JSON structure correctly represents errors for these nested fields?
A{"errors": ["user.name: Required", "user.age: Must be number"]}
B{"errors": {"user": {"name": "Required", "age": "Must be number"}}}
C{"errors": {"user.name": "Required", "user.age": "Must be number"}}
D{"errors": {"user_name": "Required", "user_age": "Must be number"}}
Step-by-Step Solution
Solution:
  1. Step 1: Understand nested error representation

    Nested fields are best represented as nested objects matching the input structure.
  2. Step 2: Match the correct nested JSON

    {"errors": {"user": {"name": "Required", "age": "Must be number"}}} nests 'name' and 'age' inside 'user', matching the input hierarchy.
  3. Final Answer:

    {"errors": {"user": {"name": "Required", "age": "Must be number"}}} -> Option B
  4. Quick Check:

    Nested errors use nested objects matching input structure [OK]
Quick Trick: Match error JSON nesting to input JSON nesting [OK]
Common Mistakes:
  • Flattening nested fields as dot-separated keys
  • Using arrays instead of objects for errors
  • Changing field names incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes