Bird
Raised Fist0

If a REST API response includes:

medium📝 Predict Output Q5 of Q15
Rest API - HATEOAS and Linking
If a REST API response includes:
{
  "user": {
    "id": 10,
    "links": {
      "orders": {"href": "/users/10/orders"}
    }
  }
}

What is the correct way to access the orders link in JavaScript from this JSON object named response?
Aresponse.orders.href
Bresponse.user.orders.href
Cresponse.links.orders.href
Dresponse.user.links.orders.href
Step-by-Step Solution
Solution:
  1. Step 1: Trace the JSON structure

    The orders link is nested inside user > links > orders > href.
  2. Step 2: Access the nested property correctly

    Use dot notation to access each level: response.user.links.orders.href.
  3. Final Answer:

    response.user.links.orders.href -> Option D
  4. Quick Check:

    Correct property access = response.user.links.orders.href [OK]
Quick Trick: Follow JSON nesting exactly to access links [OK]
Common Mistakes:
MISTAKES
  • Skipping the links property
  • Accessing orders directly under response
  • Using incorrect property names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes