Bird
Raised Fist0

A developer writes this JSON snippet for related links:

medium📝 Debug Q7 of Q15
Rest API - HATEOAS and Linking
A developer writes this JSON snippet for related links:
{
  "links": {
    "profile": {"href": "/users/1/profile"},
    "profile": {"href": "/users/2/profile"}
  }
}

What is the problem with this snippet?
AThe href values are invalid URLs
BDuplicate keys cause the first profile link to be overwritten
CThe links object should be an array
DThe profile key should be nested inside user
Step-by-Step Solution
Solution:
  1. Step 1: Identify duplicate keys in JSON object

    JSON objects cannot have duplicate keys; the second "profile" overwrites the first.
  2. Step 2: Understand effect on data

    Only the last "profile" link remains, losing the first link information.
  3. Final Answer:

    Duplicate keys cause the first profile link to be overwritten -> Option B
  4. Quick Check:

    Duplicate keys overwrite earlier ones [OK]
Quick Trick: Avoid duplicate keys in JSON objects [OK]
Common Mistakes:
MISTAKES
  • Thinking JSON allows duplicate keys
  • Assuming arrays are always required
  • Confusing key placement with nesting

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes