Bird
0
0

You want to show an example response for a REST API endpoint that returns a list of users with their IDs and names. Which JSON structure is best?

hard📝 Application Q8 of 15
Rest API - API Documentation

You want to show an example response for a REST API endpoint that returns a list of users with their IDs and names. Which JSON structure is best?

A{ "1": "Anna", "2": "Ben" }
B[ { "id": 1, "name": "Anna" }, { "id": 2, "name": "Ben" } ]
C{ "users": [ { "id": 1, "name": "Anna" }, { "id": 2, "name": "Ben" } ] }
D{ "users": { "1": "Anna", "2": "Ben" } }
Step-by-Step Solution
Solution:
  1. Step 1: Understand common JSON response patterns for lists

    Wrapping the list in a key like "users" is clear and common.
  2. Step 2: Compare options for clarity and structure

    { "users": [ { "id": 1, "name": "Anna" }, { "id": 2, "name": "Ben" } ] } uses an array of objects with id and name inside "users" key, which is best practice.
  3. Final Answer:

    { "users": [ { "id": 1, "name": "Anna" }, { "id": 2, "name": "Ben" } ] } -> Option C
  4. Quick Check:

    List of users = array inside "users" key [OK]
Quick Trick: Wrap lists in a named key for clarity [OK]
Common Mistakes:
MISTAKES
  • Returning raw arrays without a key
  • Using object with IDs as keys instead of array
  • Mixing object and array structures incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes