Bird
0
0

Which JSON structure best represents errors for both the email and nested address.zipcode fields?

hard📝 Application Q15 of 15
Rest API - Error Handling

You want to design a nested error response for a REST API that validates a user profile with nested address fields. Which JSON structure best represents errors for both the email and nested address.zipcode fields?

A{ "error": { "email": "Invalid", "address.zipcode": "Missing" } }
B{ "error": { "fields": { "email": "Invalid", "address": { "zipcode": "Missing" } } } }
C{ "error": [ { "email": "Invalid" }, { "address": { "zipcode": "Missing" } } ] }
D{ "error": "Invalid email and missing zipcode" }
Step-by-Step Solution
Solution:
  1. Step 1: Understand nested error reporting for nested fields

    Nested fields like address.zipcode should be represented as nested objects.
  2. Step 2: Evaluate JSON options for nested structure

    { "error": { "fields": { "email": "Invalid", "address": { "zipcode": "Missing" } } } } uses a 'fields' object with 'email' error and nested 'address' object containing 'zipcode' error.
  3. Final Answer:

    { "error": { "fields": { "email": "Invalid", "address": { "zipcode": "Missing" } } } } -> Option B
  4. Quick Check:

    Nested fields use nested objects = { "error": { "fields": { "email": "Invalid", "address": { "zipcode": "Missing" } } } } [OK]
Quick Trick: Use nested objects for nested field errors [OK]
Common Mistakes:
  • Using dot notation keys instead of nested objects
  • Flattening nested errors into arrays
  • Combining all errors into one string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes