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,
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);
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?'
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);
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).
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.
I believe this has been done already.
Take a look at this jQuery extension: jFeed - RSS/ATOM feed parser
jQuery.getFeed(options);
Options:
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);