unjsonify-diaspora: A shell script for extracting post Markdown source

I've needed to do this often enough, and gotten it wrong sufficiently many times, that I've finally written a simple shell script using jq and sed, to return straight Markdown from a Diaspora post. It mostly makes re-editing typos easier.

#!/bin/sh

jq -M .text | sed 's/^"//; s/"$//; s/\\r\\n/\n/g; s/\\"/"/g'

Saved as unjsonify-diaspora.

This extracts the '.text' element, trims leading and trailing quotes, replaces \r\n sequences with linefeeds, and unescapes quotes. Some further substitutions may be required though so far it seems good.

"But how do you get the JSON" you ask? Simple: append .json to any Diaspora URL.

For example: https://joindiaspora.com/posts/c7415d50e97f01385366002590d8e506

Becomes: https://joindiaspora.com/posts/c7415d50e97f01385366002590d8e506.json

You can either copy/paste the rendered content to the script, or (preferable) use a web uttility such as curl or wget to pipe directly to the script:

curl --silent https://joindiaspora.com/posts/c7415d50e97f01385366002590d8e506.json |
     unjsonify-diaspora

Usually I'm doing this to fix typos, so you could send this on to an editor:

curl --silent <url> | unjsonify-diaspora | vim -

Then delete your old, buggy post and replace it with a new buggy one.

#json #jq #ShellScripts #JustLinuxThings #linux #diaspoa #tips

6