Okay, well here is a sample players collection with two players, in JSON format (I pretty printed it):
CODEBOX
{
"fantasy_content":{
"xml:lang":"en-US",
"yahoo:uri":"\/fantasy\/v2\/game\/242\/players;count=2;start=0",
"game":[
{
"game_key":"242",
"game_id":"242",
"name":"Football",
"code":"nfl",
"type":"full",
"url":"http:\/\/football.fantasysports.yahoo.com\/f1","season":"2010"
},
{
"players":{
"0":{
"player":[
[
{
"player_key":"242.p.8801"
},
{
"player_id":"8801"
},
{
"name":{
"full":"Chris Johnson",
"first":"Chris",
"last":"Johnson",
"ascii_first":"Chris",
"ascii_last":"Johnson"
}
},
{
"editorial_player_key":"nfl.p.8801"
},
{
"editorial_team_key":"nfl.t.10"
},
{
"editorial_team_full_name":"Tennessee Titans"
},
{
"editorial_team_abbr":"Ten"
},
{
"bye_weeks":{
"week":"9"
}
},
{
"uniform_number":"28"
},
{
"display_position":"RB"
},
{
"image_url":"http:\/\/l.yimg.com\/a\/i\/us\/sp\/v\/nfl\/players_l\/headshots\/20100903\/8801.jpg?x=46&y=60&xc=1&yc=1&wc=165&hc=215&q=100&sig=Pw6JaMEEqffWUkzcdUI0dQ--"
},
{
"is_undroppable":"0"
},
{
"eligible_positions":[
{
"position":"RB"
}
]
},
{
"has_player_notes":1
},
{
"has_recent_player_notes":1
}
]
]
},
"1":{
"player":[
[
{
"player_key":"242.p.8261"
},
{
"player_id":"8261"
},
{
"name":{
"full":"Adrian Peterson",
"first":"Adrian",
"last":"Peterson",
"ascii_first":"Adrian",
"ascii_last":"Peterson"
}
},
{
"editorial_player_key":"nfl.p.8261"
},
{
"editorial_team_key":"nfl.t.16"
},
{
"editorial_team_full_name":"Minnesota Vikings"
},
{
"editorial_team_abbr":"Min"
},
{
"bye_weeks":{
"week":"4"
}
},
{
"uniform_number":"28"
},
{
"display_position":"RB"
},
{
"image_url":"http:\/\/l.yimg.com\/a\/i\/us\/sp\/v\/nfl\/players_l\/headshots\/20100903\/8261.jpg?x=46&y=60&xc=1&yc=1&wc=165&hc=215&q=100&sig=_xAFTbo7jcxfkCVyTkZmTg--"
},
{
"is_undroppable":"0"
},
{
"eligible_positions":[
{
"position":"RB"
}
]
},
{
"has_player_notes":1
},
{
"has_recent_player_notes":1
}
]
]
},
"count":2
}
}
],
"time":"349.18189048767ms",
"copyright":"Data provided by Yahoo! and STATS, LLC"
}
}
As you can see there are a few weird things here.
1. First, the "game" object is a list with two hashes* in it. Since I can't trust that these will always show up in the same order, I have to manually look into the hashes to see what's in each one. Not really a big deal, but weird. The second hash has one element, called "players". Maybe it's better to use a hash for the "game" object, something like "game_metadata" could be the key for the first element and "players" the key for the second...
2. Secondly, "players" is a hash containing numbers as keys... and one of the keys is the string "count." So if I make a list of all the keys of "players" and traverse it in order to find "player" objects, I have to check that I'm not getting the "count" object on each iteration. Again, not the end of the world, but weird. If it were me, I'd have a hash with an element called "count" and an element called "players_list" or "players_hash" that holds the actual "player" objects.
3. Okay, so then we get into the player object... a list which contains one list. Still weird.
4. Finally, we get into the "player" object, which (once we nest down one list; see point 3), is really just a list of one element hashes. Just using a hash instead is clearly a better solution for a few reasons: it's quicker and easier to program in languages that support hashes and lists (perl, python, etc), and it doesn't require a list traversal just to find an element.
5. Finally, there's some weirdness when you look at "bye_weeks" - shouldn't this be a list of "week" objects? In the current scheme, how do you handle players with multiple bye weeks (maybe they get traded). And if you assume each player can have only one bye week, then is the "week" object even necessary? You could just have "bye_week" which would hold an integer.
Okay, so I'm nitpicking on some of these, especially 5. But I think that 1, 2 and 4 deserve some thought.
Sean, I'm sure your internal data representation makes plenty of sense, and I also imagine it's something you can't just start changing around! As you alluded to, it seems like your json_encode function does some weird stuff. I don't really use PHP so I don't know much about that... but perhaps an alternate implementation with different behavior is a good solution here.
I'm new here so I don't know how this community works, but I'd be willing to contribute if anyone thinks these are good ideas.
- Brian Waters
* To be clear, what I'm calling a hash, you might alternately know as an associative array, dictionary or map.
P.S. Sean, thanks for your awesome support and interest in these forums.