RSS to JSON Convertor

This script is capable of taking an RSS (or Atom) feed and converting it into a valid JSON object. I currently cache feed requests once per hour, to save on bandwidth – so keep that in mind when developing an application.

You can use the interface that I have setup, below, or you can download the script itself (written in Perl) and run it on your own server (which is preferable).

Interface

This script currently has a REST interface, accessible via a GET request. The full request would look something like this:
GET https://johnresig.com/apps/rss2json/?url=URL&callback=CALLBACK
the URL parameter would contain the URL of the RSS/Atom feed which you are attempting to convert. The optional Callback parameter would reference a callback function that you wish to have called, with the new data.

You can test this out by visiting the following URL:
https://johnresig.com/apps/rss2json/?url=https://johnresig.com/index.rdf

Sample Code and Demo

A simple, sample, program would look something like this:

getRSS("http://digg.com/rss/index.xml", handleRSS);

function handleRSS(rss) {
  alert( "Dowloaded: " + rss.title );
}

function getRSS(url, callback) {
  feedLoaded = callback;
  var script = document.createElement('script');
  script.type = 'text/javascript';
  script.src = "https://johnresig.com/apps/rss2json/?url=" + url 
    + "&callback=feedLoaded&t=" + (new Date()).getTime();
  document.getElementsByTagName("head")[0].appendChild(script);
}

I’ve also setup a more advanced demo, which uses some tweaked code from the del.icio.us JSON page.

Also, the del.icio.us popular widget that I made using the Google Homepage API also uses the RSS to JSON convertor. Taking a quick peak at the source code shows it in use.

Download

If you wish to run your own copy of the RSS to JSON script, you can download it from here. It’s a Perl-based CGI script which requires that the following modules be installed: LWP and XML::Feed.

This work is licensed under a Creative Commons Attribution 2.5 License.

Posted: December 17th, 2005


Subscribe for email updates

16 Comments (Show Comments)



Comments are closed.
Comments are automatically turned off two weeks after the original post. If you have a question concerning the content of this post, please feel free to contact me.


Secrets of the JavaScript Ninja

Secrets of the JS Ninja

Secret techniques of top JavaScript programmers. Published by Manning.

John Resig Twitter Updates

@jeresig / Mastodon

Infrequent, short, updates and links.