0

Build 17991: Single-element JSON arrays are corrupted into JSON objects

http://www.yqlblog.net/blog/2011/06/03/cha...or-build-17991/

QUOTE
New Feature Highlights

* Single-element JSON arrays are corrupted into JSON objects


What was the reason for this change?

As it stands now, developers will have to do a type check to see if the result is an array or not.

I can imagine quite a few apps are having problems now because they assume the result will come as an array.

If you feel this was an important "feature" then fine, but at least make it backward compatible and only enable it if the developer explicitly asks for it in the query!

Regards
Jesper

5 Replies
  • I agree, for example the code supplied for this tutorial (http://developer.yahoo.com/yql/guide/yql-tutorials.html) would stop working with this change.
    0
  • The change you are referring to was made in the context of the much wider "Enable round trip lossless JSON processing" change. This change attempts to preserve the structure of a JSON response as it was received from a downstream service. There had been many complaints about the YQL engine "corrupting" the original (downstream) JSON response, including converting single-element JSON arrays into JSON objects, requiring special logic in the client to compensate for this.
    For example, see http://www.wait-till-i.com/2010/09/22/the-...-reason-for-it/

    The "Enable round trip lossless JSON processing" feature is not currently enabled by default, but can be requested by specifying "jsonCompat=new" with your query. It is our goal to enable it by default in a future release.

    Jan
    0
  • QUOTE (jan @ Jun 14 2011, 07:51 AM) <{POST_SNAPBACK}>
    The "Enable round trip lossless JSON processing" feature is not currently enabled by default, but can be requested by specifying "jsonCompat=new" with your query. It is our goal to enable it by default in a future release.

    Jan, can you provide an example query that shows how to use "jsonCompat=new"? It's not clear to me where it should be appended. To the YQL query itself? To the URL query string? So far, nothing I've tried has prevented single-item JSON arrays from being converted to objects.

    - Ryan
    0
  • Ryan, sure! It should be appended to the URL query string, as in http://query.yahooapis.com/v1/public/yql?q=[...]&jsonCompat=new

    Jan
    0
  • Ah, thanks. I think I see the problem. My query is using an open table that selects an itemPath in a JSON response. Even with jsonCompat=new, this still results in an array for multiple items and an object for a single item, which I can see being the expected behavior since YQL doesn't know that the single item should be returned in an array.
    0

Recent Posts

in YQL