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">
<head>
<title>Blogring | Thejesh GN </title>
<dateCreated></dateCreated>
<dateModified></dateModified>
<ownerName>Thejesh GN</ownerName>
</head>
<body>
    <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 -%}
    </outline>
</body>
</opml>

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,243 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 […]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.