Skip to main content


Useful Diaspora* jq recipes: Extract the last (or other specified) comment(s) on a post


if you want to re-write the most recent comment on a thread, and retrieve the original Markdown, you can fetch the post using its GUID URL with .json appended, then run it through a simple jq recipe:
curl -s '<post_url>.json' |
   jq -r '.interactions.comments[-1].text' 

Say, for example, if you realise you'd just muffed your most recent contribution to a thread and wanted to rewrite it, but don't want to have to re-tag all the Markdown from scratch.

I'm using curl as the web transport and piping output to jq on a commandline. This is supported on Linux, the BSDs, MacOS, Windows (using Cygwin or WSL), and via Termux on Android. Sorry, iOS, here's a dime, go buy a real computer.

An example referencing a specific post:
curl -s 'https://diaspora.glasswings.com/posts/ed03bc1063a0013a2ccc448a5b29e257.json' |
    jq -r '.interactions.comments[-1].text' 

Note that comments are indexed from either the start (beginning with [0]) or via negative values, the last ([-1] instance), and you can provide another offset if you're trying to access a specific post some number of values from the start or end. The third comment would be [2], the fourth most recent would be [-4].

Leave the iterator unspecified to select all comments:
jq -r '.interactions.comments[].text`

As before, the -r argument outputs raw text without JSON escaping of quotes and other characters. This avoids most post-retrieval processing, e.g., a sed script to remove quoted characters and the like.

And as I've mentioned previously, jq itself is an extraordinarily useful, if occasionally opaque, command-line tool for processing and parsing JSON data. Which happens to be how Diaspora* delivers much of its content.

This post is of course based on a comment I'd made to this earlier jq thread ... as a comment. Edited and adapted, but substantially similar.

https://diaspora.glasswings.com/posts/ed03bc1063a0013a2ccc448a5b29e257

# # # # #