Using JSON as a blog RSS feed

JSON is gaining its momentum. Many websites have started using this format as their default format of choice for data exchange. One of the main reasons behind this choice is that JSON is a simple and lightweight format. RSS, on the other hand, is basically XML, implying that this format is more suitable when you have to deal with complex data structures, since XML is particularly useful for adding semantics to describe data (think about RDF, for example).

An RSS feed, in its basic structure, is actually simpler than most developers think. For example, take a look at the following excerpt taken from a sample RSS feed:

<?xml version="1.0"?>
<rss version="2.0">
   <channel>
      <title>Liftoff News</title>
      <link>http://liftoff.msfc.nasa.gov/</link>
      <description>Liftoff to Space Exploration.</description>
      <language>en-us</language>
      <pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate>
      <lastBuildDate>Tue, 10 Jun 2003 09:41:01 GMT</lastBuildDate>
      <docs>http://blogs.law.harvard.edu/tech/rss</docs>
      <generator>Weblog Editor 2.0</generator>
      <managingEditor>editor@example.com</managingEditor>
      <webMaster>webmaster@example.com</webMaster>
      <item>
         <title>Star City</title>
         <link>http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp</link>
         <description>How do Americans get ready to work with Russians aboard the International Space Station? They take a crash course in culture, language and protocol at Russia's <a href="http://howe.iki.rssi.ru/GCTC/gctc_e.htm">Star City</a>.</description>
         <pubDate>Tue, 03 Jun 2003 09:39:21 GMT</pubDate>
         <guid>http://liftoff.msfc.nasa.gov/2003/06/03.html#item573</guid>
      </item>
      <!--more item elements here-->
   </channel>
</rss>

As you can see, this is not a too complex structure. Using JSON, you can rewrite the above feed like so:

{"rss": {

    "channel": {
    
        "title": "Liftoff News",
        "link": "http://liftoff.msfc.nasa.gov/",
        "description": "Liftoff to Space Exploration",
        "language": "en-us",
        "pubdate": "Tue, 10 Jun 2003 04:00:00 GMT",
        "lastbuilddate": "Tue, 10 Jun 2003 09:41:01 GMT",
        "docs": "http://blogs.law.harvard.edu/tech/rss",
        "generator": "Weblog Editor 2.0",
        "managingEditor": "editor@example.com",
        "webmaster": "webmaster@example.com",
        
        "item": [
        
            {
             "title": "Star City",
             "link": "http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp",
             "description": "...",
             "pubdate": "Tue, 03 Jun 2003 09:39:21 GMT",
             "guid": "http://liftoff.msfc.nasa.gov/2003/06/03.html#item573"
            
            }
            
            // more items here
        
        ]
    
    }

}
}

This is only a showcase to demonstrate that some peculiarities of the JSON format are really interesting from a development point of view. Most of all, a JSON feed is noticeably faster to parse than a normal XML/RSS feed and requires less resources. Further, all server-side languages include some methods or functions to encode and decode JSON data. Finally, it's worth to be mentioned that now the vast majority of web browsers are able to parse JSON natively.

Leave a Reply

Note: Only a member of this blog may post a comment.