Is there any reason not to build JSON data that can be indexed by some key? For example in the WhenIWork API below, using the user's id to quickly access the data? The reason I'm asking is because it seems that for a lot of uses on the client side you could easily index into the array then and grab the data you need vs. looping through the JSON array looking for a specific id. But a lot of APIs do not do this (2 of those examples below).
{
"users": [
{
"id": 4364,
"login_id": 2112,
"first_name": "Goldie",
"last_name": "Wilson",
},
{
"id": 27384,
"login_id": 2112,
"email": "[email protected]",
"first_name": "Jennifer",
"last_name": "Parker",
}
]
}
[
{
"type": "Event",
"public": true,
"payload": {
},
"repo": {
"id": 3,
"name": "octocat/Hello-World",
"url": "https://api.github.com/repos/octocat/Hello-World"
},
"actor": {
"id": 1,
"login": "octocat",
"gravatar_id": "",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"url": "https://api.github.com/users/octocat"
},
"org": {
"id": 1,
"login": "github",
"gravatar_id": "",
"url": "https://api.github.com/orgs/github",
"avatar_url": "https://github.com/images/error/octocat_happy.gif"
},
"created_at": "2011-09-06T17:26:27Z",
"id": "12345"
}
]
In my specific case I have a users portion of the API which gives me data similar to the code above. Then by going to users/availability
I can get all the availability for users. But right now I have to loop through all the data looking for specific IDs.
{
[
{
"user_id":"41",
"date":"2017-07-01",
"status":"Unavailable"
},
{
"user_id":"41",
"date":"2017-07-02",
"status":"Available"},,
[
{
"user_id":"47",
"date":"2017-07-01",
"status":"Available"
},
{
"user_id":"47",
"date":"2017-07-02",
"status":"Leave\/TDY"
}
]
}