0

JSON Format question

Doesn't look like the forum is getting any love from Yahoo! these days, but maybe someone can help.  I'm using the API to access data for this year's Baseball league.  I need to use the JSON format; retooling other parts of my app stack to XML would be prohibitive at the moment, and I'd prefer to avoid transcoding if I can.  However, the JSON i'm getting back is laid out oddly.  For example, consider the following API request (League ID and Guids elided):

http://fantasysports.yahooapis.com/fantasy/v2/team/268.l.XXXXX.t.2?format=json

here's the result, pretty-printed by my text editor:

{

    "fantasy_content": {

        "xml:lang": "en-US",

        "yahoo:uri": "\/fantasy\/v2\/team\/268.l.XXXXX.t.2",

        "team": [[{

            "team_key": "268.l.XXXXX.t.2"

        },

        {

            "team_id": "2"

        },

        {

            "name": "No Celery Cap"

        },

        {

            "is_owned_by_current_login": 1

        },

        {

            "url": "http:\/\/baseball.fantasysports.yahoo.com\/b1\/XXXXX\/2"

        },

        {

            "team_logos": [{

                "team_logo": {

                    "size": "medium",

                    "url": "http:\/\/socialentities.zenfs.com\/images\/XXXXXXXXXX_48.jpeg"

                }

            }]

        },

        [], 

    {

            "waiver_priority": 3

        },

        [], 

    {

            "number_of_moves": "3"

        },

        [], 

    {

            "managers": [{

                "manager": {

                    "manager_id": "2",

                    "nickname": "Jason",

                    "guid": "XXXXX",

                    "is_current_login": "1"

                }

            }]

        }]],

        "time": "69.392919540405ms",

        "copyright": "Data provided by Yahoo! and STATS, LLC"

    }

}


Questions:  Why does the "team" key contain an array of arrays of objects?     The inner array seams to represent the team, but instead of an object with key/value pairs like so:


{
  "team_key" : "268.1.XXXXX.t.2",
  "team_id" : "2",
  "name" : "No Celery Cap",
  // etc...
}

instead each property is a separate object, and these "property objects" are passed as an array.  Note that the properties of the outer fantasy_content object don't have this layout; nor do the team_logo or manager (inner) objects present in the reply.  Note also that some of the members of the inner array are empty arrays.  Do these represent sub-collections that weren't retrieved?


Is this a known issue, and is it documented anywhere?  I'd prefer to be able to use JSON.parse() on the data returned by the api calls, but the layout of many of the objects returned have this issue, making it more difficult to use.  At the moment it looks like I'll need to run some kind of transformation on the results - exactly what I wanted to avoid by using JSON in the first place.

Thanks,
Jason

by
1 Reply
    • Apr 25, 2012
    PS - I have no idea why the forum is showing my name as Anonymous.  If anyone can point me where to fix that, I will.

    Thanks,
    Jason
    0

Recent Posts

in Fantasy Sports API