Close and Go BackBack to Viget

Displaying Your FeedStitch JSON Feed Using jQuery

Keith Muth
Keith Muth, ON THE TOPIC OF Javascript and Tips and Tricks
Apr15 4

In this post I'm going to show you how to display your FeedStitch feed on your site using a few simple lines of jQuery. FeedStitch is a site we made to allow users to aggregate feeds quickly and easily, and then offer various output options for the feeds users create. When FeedStitich first launched Mark Cornick wrote about parsing FeedStitch’s JSON feed with plain old JavaScript. As he pointed out, his example was just one way to do it and is less bulky than including the entire jQuery library, but it is a little more complex for people not accustomed to writing straight JavaScript. The designers here at Viget use the jQuery framework for most of our JavaScript needs so we usually have the library loading into most of our sites anyway. One of the great features in jQuery is that it can easily parse JSON feeds using the $.getJSON() function. This is something I have touched on before in my previous post about pulling your Flickr feed.

For this example, I made a FeedStitch feed with all the Viget blogs aggregated into single feed. If you go to a FeedStitch feed, you can grab the JSON feed at the very bottom of the page (next to the RSS feed icon). When looking at the raw JSON feed you'll probably see a mess of all kinds of variables and text, but here is what the beginning of the FeedStitch JSON feed looks like if we format it nicely:

({"group":
 {           
  "slug": "viget-feeds",
  "entries": [
  {              
   "unique_id": "tag:viget.com,2009:extend/4.1539",
   "title": "Look Out! It\u2019s Developer Day in DC!",
   "raw_content": "\r\n\r\n\r\n <p>That's right...",
   "url": "http://feedproxy.google.com/...",
   "raw_title": "Look Out! It\u2019s Developer Day...",
   "feed_id": 48,
   "content": "\r\n\r\n\r\n <p>That's right...",
   "published_at": "2009-04-15T10:05:00Z",
  },
...and the feed continues with even more groups of "entries"

Each of those variables inside "entries" is something jQuery can latch onto so we just need to tell it how to find them. For this example we'll use the variables "title" and "url". Here is the jQuery to pull the ten latest posts from my FeedStitch feed:

$(document).ready(function(){
 
 //Tell the function where the feed is located
 $.getJSON("http://feedstitch.com/keith/viget-feeds.json?callback=?", function(data){
  
  //Grab each of the "entries"
  $.each(data.group.entries, function(i,item){
   
   //Only grab "entries" 10 times
   if(i < 10){
    
    //Create the links and throw them 
    //into the body of the page
    $("body").append("<p><a href='"+item.url+"'>"+item.title+"</a></p>");
   }
  });
 });        
});

Obviously making individual links inside paragraph tags probably isn't what you want to be doing; it is just an easy example. You can tailor what markup is being created depending on your needs. The great thing is that this can be applied to any of the FeedStitch JSON feeds, and understanding how this works will allow you to use jQuery to parse any JSON feed.

Here is a link to my example where I created links inside a list using jQuery, similar to what Mark had done in his article

So, you might be asking yourself "Why use FeedStitch when I can use Yahoo Pipes?" Good question, and I have gotten that question a lot. The answer is that you could do the exact same thing we made here with Yahoo Pipes since it offers a JSON feed as well. I actually think its an amazing service and I encourage everyone to try it out. Yahoo Pipes is great because it can do A LOT but for that reason it can be complicated for some people. FeedStitch was created to make it easy for anyone to do one thing: make a single aggregated feed of all their other feeds. Plus, you can share your FeedStitch feed with other people so it has more of a "community" feel to it. Try it out!

Sara said on 04/26 at 09:42 PM

Wow, awesome design!
This is a wordpress blog?

if it is, you can tell me how do you see in the archives just the first three letters of the month and the last two of the year? thank you very much!!!

Sara

Nicholas Tolson said on 04/27 at 08:42 AM

This sort of elegant code that does a fairly complex task makes this old man want to start yelling, “Back in my day...” type of exaggerations.

“… With your fancy jQuery and JSON! We used JavaScript 1.0, and we LIKED IT!”

Nice work, Keith. Bookmarking this one.

Doug Avery said on 04/27 at 08:53 AM

@Sara - This is an ExpressionEngine blog, but EE uses the same principles Wordpress does for displaying date formats. You can read more about PHP’s date formatting here.

Christian said on 05/15 at 11:19 AM

First of all thanks for this enlightning tutorial post. Helps a lot!

I’m currently trying to set up and modify the way my JSON feed is displayed. Is there a way get the source/service of single feed items - such as twitter/flickr/delicious - to add related icons to the parsed output?

Any hint or guidance is much appreciated.

Take care… Christian

Commenting is not available in this weblog entry.

We're The Designers

at Viget Labs. We write about design news, trends, techniques, buildout, inspiration, CSS, and our projects.

What's a-twitter?

Follow us @VigetInspire for updates of the goings-on here or @Viget for more from all of the Viget crew. #thatisall

Recent Comments

Maybe you should update the post mindy; not ebody reads the comments.

Subscribe to Comments RSS RSS

Contact Us

Have any questions, comments, ideas, or secrets to share? Let us know.


How many minutes in an hour?

Sorry, you need to have Javascript enabled to use this form. (Don't blame us, blame the spammers!) If you'd like to contact us, please visit our Contact page.