Which path to use in itemPath?
When creating a YQL table, one has to specify an itemPath in the element of the table. According to the YQL documentation this it开发者_运维知识库emPath should contain:
A dot-path that points to where the repeating data elements occur in the response format. These are the "rows" of your table.
If I specify the itemPath like this then I would "loose" some data in certain situation. e.g. in the example below I would loose the following key/value pairs:
- response => perpage, total, last_offset, page, window, offset, hidden
- request => all key/value pairs are lost
Some of these keys are maybe not that interesting because they are used for pagination only but I might still be interested in some of them e.g. total.
So my question is:
Should I in this situation just specify the itemPath json.response
which will give me the whole response, or should I specify json.response.list
which will only give me the items in the list but I have to accept to loose some data?
Example:
http://otter.topsy.com/experts.xml?q=nosql
You will get an response like this:
{"response"=>
{"list"=>
[{"topsy_author_url"=>"http://topsy.com/twitter/al3xandru",
"hits"=>819,
"name"=>"Alex Popescu",
"nick"=>"al3xandru",
"url"=>"http://twitter.com/al3xandru",
"photo_url"=>
"http://a2.twimg.com/profile_images/1260935149/carmel_head_sk_sm_normal.jpg",
"influence_level"=>"10",
"description"=>
"Founder/CTO InfoQ.com, Software architect, Web aficionado, Speaker, NOSQL Dreamer http://nosql.mypopescu.com"},
{"topsy_author_url"=>"http://topsy.com/twitter/rgaidot",
"hits"=>957,
"name"=>"R\303\251gis Gaidot",
"nick"=>"rgaidot",
"url"=>"http://twitter.com/rgaidot",
"photo_url"=>
"http://a1.twimg.com/profile_images/1266738841/avatar-6_normal.jpg",
"influence_level"=>"10",
"description"=>"digital/technology enthusiast"},
...],
"perpage"=>15,
"total"=>113105,
"last_offset"=>18,
"page"=>1,
"window"=>"a",
"offset"=>0,
"hidden"=>1},
"request"=>
{"response_type"=>"json",
"resource"=>"experts",
"parameters"=>{"q"=>"nosql"},
"url"=>"http://otter.topsy.com/experts.json?q=nosql"}}
Which itemPath
you choose to use for your table depends on how the table is intended to be used. If only the response.list
information will ever be wanted, then set that as the itemPath
. If the request
, or non-list
, information will be sometimes useful then broaden the path.
There is the option of adding a parameter to the table to allow consumers to specify the itemPath
, like other tables do, and have it default to the most common use case. Alternatively, the table could allow some flag in the query that dictates whether to return just the list of results or the whole original response.
Personally, I would likely just go with json.response.list
.
精彩评论