Search code examples
xmljsonfeedyahoo-pipes

How to convert JSON to XML? (preferably with Yahoo Pipes or Ruby)


There is plenty of information on XML to JSON conversion... But I would like to convert a JSON result into XML.

For example the iTunes Search API only provides output in the JSON format.

http://itunes.apple.com/WebObjects/MZStoreServices.woa/ws/wsSearch?term=jack+johnson&country=US&media=music&entity=musicArtist&limit=6&genreId=&version=2&output=json&callback=jsonp1279429984094

I would like to consume this JSON result as an XML feed (to be read by any standard feed reader).

If I could offload the work to Yahoo Pipes that would be great (it's a free service and would reduce the load on my server).

As an side my site is being built with Ruby / Sinatra - hosted on Heroku.


Solution

  • It's quite easy to do with Yahoo! Pipes or with YQL. This is what I ended up with when using this query:

    select * from json
        where url='http://itunes.apple.com/WebObjects/MZStoreServices.woa/ws/wsSearch?term=jack+johnson&country=US&media=music&entity=musicArtist&limit=6&genreId=&version=2&output=json&callback='
    

    URL:

    http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20json%20where%20url%3D'http%3A%2%2Fitunes.apple.com%2FWebObjects%2FMZStoreServices.woa%2Fws%2FwsSearch%3Fterm%3Djack%2Bjohnson%26country%3DUS%26media%3Dmusic%26entity%3DmusicArtist%26limit%3D6%26genreId%3D%26version%3D2%26output%3Djson%26callback%3D'