Converting JSON to RSS Feed (Using Meetup API)
I love meetups. But I hate finding out about a cool meetup the week of (or week before), after their RSVP list is completely full. What I wanted was to have an RSS feed of every event for all my groups, as they're posted, which I could review with all my other rss feeds.
Unfortunately, Meetup doesn't have a native way of getting an rss feed with events from all your groups. However, they do have a pretty cool API that returns a json object of all events that match specified parameters. I wish I could have used their events api directly, but the available formats were json and xml.
Thankfully, someone else has already partially solved the problem of creating an rss feed from json object (instructions, code). From that, I was able to create my own json to rss feed generator for meetup: https://script.google.com/macros/s/AKfycby-nBW5B0zaP8mFSoytWwZyPEzoqo4SnfeM-OJdhWakciMTN9S8/exec (code).
How to Use:
If you want to subscribe to a list of events from my groups, just go directly to that google script url.
However, the beauty of this url is that it also accepts parameters. All you need to do is get the url you want to generate an rss feed from using the API Console
Then, add that url as a parameter to the google script url:
https://script.google.com/macros/s/AKfycby-nBW5B0zaP8mFSoytWwZyPEzoqo4SnfeM-OJdhWakciMTN9S8/exec?url=>
That's it! Use this url as the RSS feed url for any feed reader (I personally use Inoreader) or automated program (like IFTTT)
Code Writing Process:
Making A Google web app
Get Google Apps Script
Making a web app is actually super easy. I had to go to Google Drive and add the Google Apps Script format.
Write doGet function for Get method
Then, using a the doGet() function, I could define what would be returned when the user visits the web app. Once I publish > deploy as web app, the web app goes live.
Use URL parameters
To make the web app dynamically change the url it generates the feed from, I accept a parameter in doGet(). This parameter has access to the url parameters.
Making a Valid XML
Validating my XML was an annoying process. I used Feed Validator and read up on formatting RSS feeds on RSS 2 specifications.
The one downside with using Google web apps to create the rss feed is that I had to keep re-deploying in order for the xml validator to be able to validate new code.
Escape special characters
First thing about XML, contents needed to be escaped (`````` did not work). To do this, I used an escapeXml function on data within xml tags other than <link> and <pubdate>:
function escapeXml(unsafe) { return unsafe.replace(/[&'"\n\r]/g, function (c) { switch (c) { case '': return '>'; case '&': return '&'; case '\'': return ''; case '"': return '"'; case '\n': return ''; case '\r': return ''; } }); }
Notice especially that while documentation doesn't explicitly mention this, escaping newlines and carriage returns are also important.
Making a Valid RSS Feed
Use RFC-822 date-time
Turns out RSS feeds need to have RFC-822 date-time within the <pubdate> field. Thankfully, this is easy to do in JavaScript, just use new Date().toUTCString()
Use dc:creator
Also, for each RSS feed item, I originally used <author> field, but turns out that RSS feeds expect this field to be an email link. So instead, I switched to <creator> for indicating the author of each post. This meant I also needed to specify <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
Add a description
One of the last things that I needed to do to make my RSS feed completely validated was to add a description.
Questions
So now that I have a working RSS feed generator, it's time to ask whether this is the BEST way to create a feed. According to some people, Atom feeds are preferable. Perhaps I should consider converting this script to an Atom generator, but for now, it works and I'm happy.











