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 http://ejohn.org/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:
http://ejohn.org/apps/rss2json/?url=http://ejohn.org/index.rdf

Sample Code and Demo

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

  1. getRSS("http://digg.com/rss/index.xml", handleRSS);
  2.  
  3. function handleRSS(rss) {
  4.   alert( "Dowloaded: " + rss.title );
  5. }
  6.  
  7. function getRSS(url, callback) {
  8.   feedLoaded = callback;
  9.   var script = document.createElement('script');
  10.   script.type = 'text/javascript';
  11.   script.src = "http://ejohn.org/apps/rss2json/?url=" + url
  12.     + "&callback=feedLoaded&t=" + (new Date()).getTime();
  13.   document.getElementsByTagName("head")[0].appendChild(script);
  14. }

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


If you particularly enjoy my work, I appreciate donations given with Gittip.

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.

Ukiyo-e Database and Search

Ukiyo-e.org

Japanese woodblock print database and search engine.


John Resig Twitter Updates

@jeresig

Infrequent, short, updates and links.