Confession time: I’ve never actually worked with a JSON feed.
I know what you’re thinking… Yes, you’re right. I’ve built a bunch of Ajax-y components and one full blown application over the past two years.
No, in light of that it doesn’t make any sense that I haven’t used JSON before.
Anyway, to actually know what I’m doing the next time, I’ve decided to play around with some feeds right here and write up what I discover to help solidify my own knowledge and to help out anyone else who might be wondering about the magical world of JSON feeds.
Did I mention that they were magical? They are. They’re made of pixie dust and rainbows.
Yes, I’ve gone slightly off the rails… ignore that last bit.
To start with, I decided to use the handy feed from one of my favorite web twenty web sites, del.icio.us. Not surprisingly, since del.icio.us kicks all kinds of ass, they make it dead easy to use JSON feeds. All it takes is attaching the script generated at http://del.icio.us/feeds/json/user_name to a document and a
posts array which contains all of the selected user’s posts.
You can read their concise documentation here. They have a nifty sample as well.
Here’s the example I whipped up. This grabs the last 15 bookmarks from my account, takes the link, description and tags and drops them all into a regular old unordered list*.
Here’s the feed itself. As you can see it contains a simple test to see if the Object already exists, an object definition and then an array populated with all of the post data. Pretty straightforward, really.
The following code sample shows how I did it. My comments are inline and in blue.
And that’s that- a run-through of the simplest possible usage of a JSON feed (at least in terms of extracting the data.) Next time (which should be soon) I’ll look at different methods for getting dynamic data out of JSON. Oh, the fun we’ll have.
note is also available- I’ll use that in my next example.