22

I am writing an RSS feed (for fun) and was looking at the spec here.

RSS is a dialect of XML. All RSS files must conform to the XML 1.0 specification, as published on the World Wide Web Consortium (W3C) website.

Obviously this means that I am not serving 'pure' RSS if I choose the JSON option. That said, if I conform to the rest of the spec, is it likely that (customised) readers will be able to parse it?

To put it another way, if I conform to the spec, but using JSON instead of XML is it a usable RSS feed?

edit I am not sure I made myself clear. There is no XML involved. I want to write something akin to RSS (which is XML) using JSON instead. Obviously the readers of such a feed would need to be written to understand the JSON format. I was wondering if this had been done already. Are there services that serve a feed this way? Are there programs that can aggregate/understand this format. Is the RSS spec (sans the XML part) a useful spec to conform to in this case?

rg

{
"title":"example.com",
"link":"http://www.example.com/",
"description":"Awesome news about junk",
"items":[
    {
        "title":"An article",
        "link":"http://www.example.com/an-article",
        "descrition":"Some sample text here",
        "pubDate":"2008-10-27 11:06 EST",
        "author":"example author",
    },
    {
        "title":"Second",
        "link":"http://www.example.com/Seond",
        "descrition":"Some sample text here",
        "pubDate":"2008-10-25 23:20 EST",
        "author":"author mcauthor",
    },
    {
        "title":"third article",
        "link":"http://www.example.com/third-article",
        "descrition":"Some sample text here",
        "pubDate":"2008-10-25 23:18 EST",
        "author":"some other author",
    }
]
} 
1
  • 3
    Alas, no, JSON was just a little too late. +1 anyway, just for thinking out of the box.
    – Tim Post
    Nov 7, 2009 at 13:04

9 Answers 9

24

No, RSS is an XML-based format, and JSON is an different language rather than some kind of dialect. RSS readers won't understand JSON.

Your question is akin to asking 'Can I speak French in Chinese?'

4
  • 5
    So there is not agreed upon standard for JSON to act as an RSS feed (not actual RSS but something that works on the same idea)? Seems like it would be a good thing to have. The RSS2.0 one could be a good start. Oct 29, 2008 at 12:49
  • 4
    @Hyposaurus I think we're getting there.
    – Jacob
    May 22, 2017 at 14:25
  • I would love to serve both and evetually only serve JSON when the industry catchup
    – benbyford
    Nov 7, 2018 at 11:30
  • The problem with JSON is it cannot stream like XML. But that doesn't mean you can't simply run RSS through XSLT 3.0 and [transform it (stackoverflow.com/a/54882328/712334) into JSON.
    – vhs
    Feb 26, 2019 at 9:35
14

I believe this has been done already.

Take a look at this jQuery extension: jFeed - RSS/ATOM feed parser

jQuery.getFeed(options);

Options:

  • url:
  • data:
  • success:

Example:

jQuery.getFeed({
       url: 'rss.xml',
       success: function(feed) {
           alert(feed.title);
       }
   });

Note that in this case, 'feed' would be a javascript object. If you wanted to pass this using JSON, you can just use the javascript JSON utility.

Example:

var myJSONText = JSON.stringify(feed);
1
9

Is the RSS spec (sans the XML part) a useful spec to conform to in this case?

If you want to invent yet another syndication format, I recommend using Atom as a base. IMHO it has much cleaner, more consistent design, and has useful features like reliable updates of past items, makes distinction between summaries and full content, etc.

I was wondering if this had been done already.

Flickr has JSON output format. They even have lolcode feed.

1
  • 5
    Voted up just for the link to the lolcode, which made me giggle most unprofessionally.
    – TRiG
    Nov 27, 2009 at 1:25
8

You're right that the client reading the feed would have to have custom support for whatever the particulars of your JSON were. So you'd either need to make a custom feed reader to consume that information, or someone would have to propose a JSON feed standard, and it'd have to be widely adopted.

Well, I think your desires have finally been met, friend!

Take a look at JSON Feed. As of this writing it's only about a week old, but it's already picking up steam, having been supported now by Feedly, Feedbin, News Explorer, NewsBlur, and more being added all the time.

If I had to pick a standard to use when generating a JSON version of RSS, I'd pick JSON Feed for sure.

1
  • Since I posted this, support has been added to Feedly, too.
    – jlbang
    Jun 22, 2017 at 20:42
3

Json.NET - http://james.newtonking.com/projects/json-net.aspx - has support to convert any XML document to JSON.

XmlDocument doc = new XmlDocument();

doc.LoadXml(@"<?xml version=""1.0"" standalone=""no""?>
<root>
  <person id=""1"">
    <name>Alan</name>
    <url>http://www.google.com</url>
  </person>
  <person id=""2"">
    <name>Louis</name>
    <url>http://www.yahoo.com</url>
  </person>
</root>");


string jsonText = JavaScriptConvert.SerializeXmlNode(doc);
//{
//  "?xml": {
//    "@version": "1.0",
//    "@standalone": "no"
//  },
//  "root": {
//    "person": [
//      {
//        "@id": "1",
//        "name": "Alan",
//        "url": "http://www.google.com"
//      },
//      {
//        "@id": "2",
//        "name": "Louis",
//        "url": "http://www.yahoo.com"
//      }
//    ]
//  }
//}

XmlDocument newDoc = (XmlDocument)JavaScriptConvert.DeerializeXmlNode(jsonText);

Assert.AreEqual(doc.InnerXml, newDoc.InnerXml);
2

There are a bunch of different ways to serialize RSS into JSON. All of them work pretty much the same way: the elements and attributes become property names, the values become property values, etc. See Piyush Shah's technique, for example, which is a .NET implementation.

Transforming arbitrary XML to JSON using XSLT is simple enough that you can find a half-dozen examples of it on Google.

As long as this is done consistently, JavaScript that can process an object model designed to replicate the data structure of the RSS specification should be able to handle the object model that the JSON deserializes into.

Who are you planning to send this JSON to? That's the real question.

1

Well, if you are developing some javascript app you might want to get any RSS feeds as JSON to overcome cross-domain querying issue. There is a reliable Google provided solution that converts about any RSS to JSON. For jQuery lover's there is a universal RSS to JSON converter plugin.

Example:

$.jGFeed('http://twitter.com/statuses/user_timeline/26767000.rss',
  function(feeds){

    // feeds is a javascript object with RSS content

  }, 10);
1

I know this is a fairly old question, and maybe irrelevant now.

However. I would suggest anyone looking to publish a RSS-like feed in JSON should use a new format that is rapidly gaining adoption; JSONFeed (https://jsonfeed.org).

-1

Are there programs that can aggregate/understand this format.

You can use XSLT 3.0 to transform XML to JSON and back to XML again. More info on how to accomplish the transforms to JSON here:

https://www.xml.com/articles/2017/02/14/why-you-should-be-using-xslt-30/.

3
  • This isn't what the author is asking
    – asciidude
    Nov 29, 2022 at 6:22
  • 1
    OP asked if they could serve web feeds using JSON. XSLT is a transform language which can produce JSON from XML.
    – vhs
    Nov 29, 2022 at 22:10
  • Interesting, but still not exactly what the author was asking lol
    – asciidude
    Dec 17, 2022 at 4:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.