0

JSON differences

Is this an example of JSON output not being the same as XML at the top level?
http://bit.ly/8N0oe
The JSON output only has the last "content" element that appears in the XML output.

by
5 Replies
  • QUOTE (hapdaniel @ Jul 14 2009, 12:32 PM) <{POST_SNAPBACK}>
    Is this an example of JSON output not being the same as XML at the top level?
    http://bit.ly/8N0oe
    The JSON output only has the last "content" element that appears in the XML output.


    Since we haven't found a satisfactory mapping from XML to JSON for sophisticated XML & HTML output we decided to implement JSONP-X. This will allow you to get the original XML string in a JSON payload in the browser.

    Sam
    0
  • QUOTE (Sam @ Jul 14 2009, 02:25 PM) <{POST_SNAPBACK}>
    Since we haven't found a satisfactory mapping from XML to JSON for sophisticated XML & HTML output we decided to implement JSONP-X. This will allow you to get the original XML string in a JSON payload in the browser.

    Sam


    That could be a teensy bit difficult for the Yahoo! Pipes users of the YQL module it has.
    0
  • QUOTE (hapdaniel @ Jul 15 2009, 04:04 AM) <{POST_SNAPBACK}>
    That could be a teensy bit difficult for the Yahoo! Pipes users of the YQL module it has.


    Here's a tutorial that might be helpful: http://paul.donnelly.org/2009/07/08/yql-and-jsonp-x/ It describes the usage of JSONP-X
    0
  • I'm having this problem as well: I've been trying to use the YQL pipes module basically as a proxy to JSON feeds, for use in Yahoo Pipes.

    (read this if want to know why I'm using YQL this way):
    I'm doing this because the "Fetch Data" module over at Yahoo Pipes doesn't seem to support Unicode, and using it results in irrecoverable loss of information. For instance, a Unicode string in a JSON result will be converted into a string such as "uXXXXuXXXXuXXXX ..." by the Fetch Data module. On my end, I tried using RegEx to replace all "unicode looking" strings (in the format of uXXXX, where XXXX are 0-F), but this can't work: Some strings are in this format, but are not actually unicode, such as the string "cubecart" where "ubeca" would get matched. Hence, some information is permanently lost when using Fetch Data.


    Anyway, in the process of switching over some pipes from "Fetch Data" to YQL, which I figured would be equivalent, I found weird behavior.

    The first is that if the name/value pairs of a JSON contain both numbers and strings, it consolidates the numbered ones into a subarray with the name "_". I haven't tested this, but I wonder what happens if the JSON object already contains a property named "_" ! At any rate, this YQL is altering the JSON in a very inconvenient way.

    Take this JSON feed, for instance: http://feeds.delicious.com/v2/json/urlinfo...eaefe4381592a46

    If you look at the "top_tags" property, you'll see there are 10 name/value pairs. YQL, however, returns this:

    http://query.yahooapis.com/v1/public/yql?q...n&callback=

    Notice in "top_tags" there is now a subarray, with the name "_".


    Another difference between YQL's returned JSON and the original JSON is that YQL will entirely omit a name/value pair if the value is an empty array. This is more serious, as in this instance the name, which may be important information, will be lost forever. (Note: it may omit name/value pairs in other instances... such as when the value is empty string, 0, or empty object... I just haven't tested this, either)

    I'm curious to know the best way to approach this issue.

    Thanks!
    0
  • Still more strangeness with YQL and how it handles JSON name/value pairs...

    YQL seems to replace the the names in some name/value pairs. If the name starts with a number, but has letters following it, such as "4hww", the number is replaced with "_". (If it's a number without a letter, it creates a subarray, as described in my last post). Even stranger, it seems like it only cares about the first digit. That is, the name of "100dollars" would be changed to "_00dollars".

    Again.. not sure what happens if the name "_00dollars" already exists... but it likely wouldn't turn out very good.

    Another thing is it seems to replace other characters with "_" as well. So the name "o&#039;reilly" (&#039; is a single quote) gets changed to "o__039_reilly. It looks like the characters &# and ; get changed to _.
    0

Recent Posts

in YQL