YQL transforms all JSON data sources into XML before returning results. To return JSON results that were obtained from a JSON data source, YQL must first transform the original JSON data to XML and then transform the XML back into a JSON result. During the tranformation from XML to JSON, the original JSON may be altered or become "lossy". In other words, the original JSON may not be the same as the returned JSON.
The original JSON may be altered in the following ways:
To prevent this "lossy" transformation, you append the query string parameter
jsonCompat=new
to the YQL Web Service URL that you are using. For those creating tables, you use the
jsonCompat("new")
when making REST calls to other Web services. To illustrate how the jsonCompat parameter is used, we'll look at the below examples that use the community table that queries the Gowalla API, which only
returns JSON.
The following REST URI uses the public YQL Web Service URL and the Gowalla table. The jsonCompat parameter is not added to the URI, so the original JSON returned from the Gowalla API will be altered in the YQL response.
http://query.yahooapis.com/v1/public/yql?q=select * from gowalla.users where id='sco' and api_key='fa574894bddc43aa96c556eb457b4009'&env=store://datatables.org/alltableswithkeys
In the returned "lossy" JSON results below, notice that last_checkins is an object and that _comments_count property has the the string value "0".
Appending the jsonCompat=new query parameter to the REST URI as seen below, YQL now returns the same JSON data as the Gowalla API.
http://query.yahooapis.com/v1/public/yql?q=select * from gowalla.users where id='sco' and api_key='fa574894bddc43aa96c556eb457b4009'&env=store://datatables.org/alltableswithkeys&jsonCompat=new
In the returned "lossless" JSON results below, the last_checkins property is now an array with a single element, and _comments_count is a number.