For some time, I’ve been thinking adding a JSON feed to this blog that contains all the post as well as relevant metadata (publication date, tags, licensing information etc.). Well, finally I got around to it.
In case your not familiar with JSON, essentially it’s a standardised format for data storage. It has the considerable advantage that is both machine and human readable. (Your browser might even include a plug-in to JSON ever more legible by adding spacing and colour coding.)
You can view the feed directly here and see the script I wrote to generate the JSON here.
This may not seem a particularly useful feature, but I do think there are some valid reason to include. I’ll discuss my rationale now, as well as the code I wrote, and some limitations.
Quite a number of blogs and news sites I follow include a JSON feed. While I can’t speak to their reasons for including one, I have found it a useful feature because it makes extracting the content of these sites quite straightforward1. As I wrote in Why I use Createve Commons, I see this blog as something of an experiment. Most of my projects are ongoing or incomplete so I’m happy for others to take them up and run with it. I feel including a JSON feed is consistent with this principle since it makes taking these posts and adjusting them quite easy.
Additionally, having a JSON feed of all my posts is helpful for archiving my writing, and potentially makes my blog more transferable. By that I mean, this blog is based on the Astro framework2. While I’m very happy with Astro, perhaps one day I might want to try something new.
Admittedly, all posts are all initially written in Markdown, which is already extremely transferable, however the method of including meta data and its format is I believe unique to Astro. So with this metadata now in a more generic JSON format it should be easier to port it and the content to a new framework later on.
The JSON file is generated by a simple Python script. All Astro markdown files include a header contain various meta data that the programme can extract. It then converts the main content into html and adds that to the entry. Lastly a separate function adds the relevant licencing information.
As far as the quality of the code goes, it basically serves its purpose i.e. generating a JSON file of my blog posts but it’s not quite as full featured as I would like. For instance the programme doesn’t check for duplicate entries and you have to run the programme for each post one by one. Better would be if you could just point it at a directory, it would check if the entry had already been included and any new ones. However, since I post quite infrequently, and there are not that many blog posts, it’s not such a hassle to rebuild the file each time I write something new.
Of course, feel free to make adjustments to the code if you think you can improve it.
Adding a JSON feed by William Samuel McDonald is licensed under CC BY 4.0