0

Lossy YQL JSON serialization

An example YQL output from

http://query.yahooapis.com/v1/public/yql?q=select * from html where url%3D"https%3A%2F%2Faddons.mozilla.org%2Fen-US%2Ffirefox%2Faddon%2F10137%2F" and xpath%3D'%2F%2Fh3[%40id%3D"reviews"]%2Ffollowing-sibling%3A%3Adiv[1]%2F%2Fp[%40class%3D"description"]'

(without &format=json) currently returns, among other things (I'm pretty-printing the whitespace for readability):

CODEBOX
<p class="description">
I'm using your Add-on version 3.6 on Mac OS 10.6.4 in Firefox 3.6.12.
Since a couple of days when I click on the "download video" button
nothing happens any more. The drop-down doesn't show up and i can't
download the video. also when i press the button to enlarge the video
(not fullscreen, just full width) the video doesn't resize (the
fullscreen button still works though). also when i click on "more"
below the video the description doesn't show. the box with the
description doesn't even open up.
<br/><br/>
Now i just tried your add-on under a new login
with an unconfigured firefox and it works perfectly.
<br/><br/>
Please tell me how i get the add-on to run again under my normal login.
</p>


Which, with &format=json, gets serialized down to this (I chopped off the first and last item not shown above, and again formatted whitespace for readability):

CODEBOX
{ "query":
{ "count": "1"
, "created": "2010-11-12T22:09:24Z"
, "lang": "en-US"
, "results":
{ "p":
[ { "class": "description"
, "br": [null,null,null,null]
, "content": "Please tell me how i get the add-on to run again\n under my normal login."
}
]
}
}
}


...which captures (some) DOM structure but not the interesting text content of the input, which is my goal.

Could you maybe change the JSON serialization to either provide the whole DOM segments captured by the XPath query, or (often more useful), pass the outerHTML of each match as strings in the JSON, i e the above JSON subset would instead have looked like this:

CODEBOX
{ "query":
{ "count": "1"
, "created": "2010-11-12T22:09:24Z"
, "lang": "en-US"
, "results":
[ "<p class=\"description\">I'm using your Add-on version 3.6 on Mac OS 10.6.4 in Firefox 3.6.12. Since a couple of days when I click on the \"download video\" button nothing happens any more. The drop-down doesn't show up and i can't download the video. also when i press the button to enlarge the video (not fullscreen, just full width) the video doesn't resize (the fullscreen button still works though). also when i click on \"more\" below the video the description doesn't show. the box with the description doesn't even open up. <br/><br/>Now i just tried your add-on under a new login with an unconfigured firefox and it works perfectly. <br/><br/>Please tell me how i get the add-on to run again under my normal login.</p>"
]
}
}


This would help a lot towards making YQL useful for browser-side usage.

--
/ Johan Sundström, http://ecmanaut.blogspot.com/

by
2 Replies
  • Johan,

    If you're using JSONP as a way to get YQL data onto your webpage, you may want to try out JSONP-X which basically sends over the xml structure in a json envelope.

    http://developer.yahoo.com/yql/guide/yql-jsonp-x.html

    This will retain all nodes you requested.


    Thanks -Paul
    YQL Team
    0
  • Brilliant! Exactly what I was looking for;

    http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22https://addons.mozilla.org/en-US/firefox/addon/10137/%22%20and%20xpath%3D'//h3[%40id%3D%22reviews%22]/following-sibling::div[1]//p[%40class%3D%22description%22]'&format=xml&callback=foo

    does indeed respond with:

    CODEBOX
    foo(
    { "query":
    { "count": "3"
    , "created": "2010-11-13T00:35:55Z"
    , "lang": "en-US"
    }
    , "results":
    [ "<p class=\"description\">Got it for MP3 conversion.\n <br/>Doesn't dowload anything just redirects to a\n site to perform the download. Deinstalled it\n immediately.\n <br/>Didn't checked other formats, I already have\n DowloadHelper that works fine and doesn't sell any\n dummy MP3 download feature, rather go for it.<\/p>"
    , "<p class=\"description\">I'm using your Add-on\n version 3.6 on Mac OS 10.6.4 in Firefox 3.6.12. Since a\n couple of days when I click on the \"download\n video\" button nothing happens any more. The\n drop-down doesn't show up and i can't download\n the video. also when i press the button to enlarge the\n video (not fullscreen, just full width) the video\n doesn't resize (the fullscreen button still works\n though). also when i click on \"more\" below\n the video the description doesn't show. the box\n with the description doesn't even open up.\n <br/>\n <br/>Now i just tried your add-on under a new login\n with an unconfigured firefox and it works perfectly.\n <br/>\n <br/>Please tell me how i get the add-on to run again\n under my normal login.<\/p>"
    , "<p class=\"description\">doesn't work<\/p>"
    ]
    });


    Thanks!
    0

Recent Posts

in YQL