Rick Cogley's Tech Logr

Short Technical Laser Bursts %%

RC Logr 20190414 135141

Sunday, 14 Apr, 2019

Given a json file, used say for a search index, you can easily use «jq» from stedolan to extract what you need from it. 👻 It is as simple as piping the json to jq, and using its powerful filtering to extract what you need. I generate the search index for this site in json, because that is what lunr requires, but it doubles as a source for the info I use to tweet about a new post.

Given a json like this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
[
  {
    "content": "Static site generator «Hugo 0.55.1» was released, with three bug fixes. Go static! 🚀 #gohugo #jamstack #golang #webdev\n",
    "ref": "https://logr.cogley.info/2019/04/12/1555079759/",
    "tags": null,
    "title": "RC Logr 20190412 233559"
  },
  {
    "content": "MacOS or Linux users, you might find log file viewer «lnav» useful. It is for viewing local log files, and requires no server like Splunk. Fire it up, press ? to toggle help or / to search. 🕵🏻‍\n",
    "ref": "https://logr.cogley.info/2019/04/12/1555047850/",
    "tags": null,
    "title": "RC Logr 20190412 144410"
  },
  {
    "content": "The first black hole...

… I use something like this to extract what I want to tweet:

1
cat index.json | jq --raw-output '.[0] | .content[:75]+"... "+.ref' 

That pipes the index json file to jq, gets the 0th (first and latest) node, then pipes it extracting and concatenating the values of the .content and .ref keys, limiting the .content value to 75 characters. With jq, concatenation to string literals is done with a plus sign. The statement within the single quotes is where the work is done, and it can be multiple filters with pipes between.

RC Logr 20190414 135141 - Given a json file, used say … Rick Cogley
Back to Home Tweet Link