Blogring – JSON to OPML export

If you have been reading this blog you would know that I have blogring now. It's stored as JSON documents in CouchDB and then used in widgets in the sidebar. It also happens that I read the same blogs in a feed reader. So I wanted a way to import these into my blog reader easily. CouchDB is my source of truth; hence I wanted a way to export JSON documents into OPML format that can be imported into any reader.

OPML (Outline Processor Markup Language) is an XML format for outliners. It's also the most popular format for exchanging feed subscriptions. So it was apparent.

There are hundreds of ways to write this export script. But I choose my most reliable tool for formatting, Jinja2, to convert from JSON to OPML.

<opml version="2.0">
<title>Blogring | Thejesh GN </title>
<ownerName>Thejesh GN</ownerName>
    <outline text="Blogring" title="Blogring of Thejesh GN">
    {%- for item in rows -%}
    {% if item['doc']['feed'] %}
    <outline title="{{item['doc']['title']}}" xmlUrl="{{item['doc']['feed']}}" htmlUrl="{{item['doc']['url']}}" type="rss" />
    {%- endif -%}
    {%- endfor -%}

And I used Jinja2 CLI to do the actual conversion. It works like a charm.

jinja2 --format=json -o ../../data/blogring.opml opml.jinja2 ../../data/blogring.js

Now I can import the OPML into my feedreader. Also, share it on the web for the rest of the world to use.

You can read this blog using RSS Feed. But if you are the person who loves getting emails, then you can join my readers by signing up.

Join 2,165 other subscribers

1 Response

  1. September 24, 2022

    […] a script to convert my JSON blogring to OPML. I have shared the OPML if you want to use […]