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.
l.m.orchard (December 18, 2005 at 9:05 pm)
Hope you don’t mind, but I borrowed your idea here for my PHP-based feed processing kit:
http://decafbad.com/blog/2005/12/18/feedmagick-gains-an-rss-to-json-filter
http://decafbad.com/2005/12/FeedMagick/
Brad Neuberg (January 18, 2006 at 4:30 pm)
You rock; this is cool.
Looks like the Delicious demo isnt working on FF 1.4 on Windows. I see nothing on the page except the headline.
John Resig (January 18, 2006 at 6:41 pm)
Yeah…. I think my domain is banned from using delicious, I’m trying to find a way to fix it – I just have too many services which utilize delicious pages, unfortunately. I’ll let you know when it’s resolved.
Oh – and I changed the demo to use digg, instead.
Greg (February 8, 2006 at 10:00 am)
Hi John,
Love it!
Ever since del.icio.us dropped support for generic JSON feeds (feeds/json/tag/*) I’ve been wondering how to get them back.
Re: load. My homepage is very low traffic (a couple of hits per day) and I won’t be integrating into my wildly popular FreshTags service, lest the ensuing hordes destroy your link.
One query: I don’t seem to be having much luck with tag intersections:
http://ejohn.org/apps/rss2json/?url=http://del.icio.us/rss/tag/science+phyics
The %2B becomes a %20. Any thoughts?
Cheers,
-Greg.
Greg (February 13, 2006 at 2:19 am)
Just to let readers know, I wrote up a use of John’s RSS2JSON service for restoring “generic JSON feeds” from delicious.
You can read about it on this Freshblog, where I guest-blog.
Three cheers for John!
-Greg.
Shinichi Tomita (February 13, 2006 at 2:41 pm)
Hello, John. I found this site while googling about JSON. Great and very useful.
Recently I created some jsonp testing tool, and I included your RSS to JSON converter in examples. Please check out and let me know if you like this.
http://www.geocities.jp/stormriders999/jsontest.html
Regards,
– Shinichi
David Galbraith (May 12, 2006 at 2:31 pm)
JSON and RSS
John Resig has a very nice RSS to JSON converter. We’ve been working on a JSON output to Solr (Lucene)…
dJsLIM (May 12, 2006 at 11:19 pm)
Hi John, great service!! This comes in __very__ handy!
I just noticed the following snippet:
issued: new Date(‘2006-05-13 04:08:30’)
in the JSON output. Is that possible a bug? I wasn’t aware of the fact
that Date object could take a string as a constructor argument.
John Resig (May 12, 2006 at 11:55 pm)
djslim: Yep – that’s perfectly valid Javascript! Works like a charm.
dJsLIM (May 13, 2006 at 12:39 am)
Oh, then is it possibly supported by some browsers and not others?
I put the following in my FireFox Javascript Console and IE address bar
alert(new Date(‘2006-05-13 04:08:30’))
(I prepended it with “javascript:” for IE)
and I get “Invalid Date” and “NaN” respectively =(
It does seem to work on Opera, though. =)
zmarties (May 19, 2006 at 2:49 am)
The problem is not with the javascript syntax, it’s with the date syntax.
Using hyphens to separate the Year-Month-Day is not standard.
new Date(‘2006/05/13 04:08:30’)
works fine however in Mozilla based browsers.
cody (May 20, 2006 at 10:35 am)
This is really cool.
One suggestion
You should probably have a flag that will generate JSON that has strings for the labels
{“Var”: 1}
to go along with
{Var: 1}
Dave (July 7, 2006 at 3:34 pm)
This is a very useful service.
One problem I am having is that if the feed contains a CF/LF in one of the RSS tags, the returned data will be truncated at that point, these should stripped out of the retuned data.
Dave
Dave Raggett (August 2, 2006 at 5:49 am)
Thanks for developing this. I tried it on a BBC news feed and found that the script truncates the content field when the src includes a double quote mark (“), as in:
The prime minister calls for “an alliance of moderation” to combat an “arc of extremism” in the Middle East.
The RSS file had the following markup for the description:
The prime minister calls for "an alliance of moderation" to combat an "arc of extremism" in the Middle East.
zhenggc (April 4, 2007 at 1:03 am)
Hope you don’t mind, but I borrowed your idea here for my Java-based feed processing kit:
http://huaco.3322.org/trac/huaco/wiki/RssToJson
and source code in
http://huaco.3322.org/trac/huaco/browser/rss2json/trunk
Bob (May 9, 2007 at 9:54 am)
JsonML http://jsonml.org is also a good way to convert any XML to JSON. It works great for RSS, ATOM or even XHTML!