A Parser for River4 JSON URLs


This post was original published on my Postach.io blog on January 21st, 2015.

River4 is an RSS feed aggregator developed by Dave Winer. It looks good on its own, but I’ve been wanting to develop my javascript chops. A while ago, I wrote a JSON-parsing script using Spotify’s API to search for albums, so I thought I’d take a stab at the JSON URLs produced by River4.

Here is the script.

The greatest impediment was that each file starts with onGetRiverStream ( and ends with ). (The actual JSON is embedded within. Here is a default river to look at.) I couldn’t figure out how to parse the file, and then I realized I could treat the file like text before parsing it. I used substring() to remove the 1st 18 characters and the final character, and then parsed the new string (which starts and ends with curly brackets). Stack Overflow was immensely helpful. See lines 13-15 below: