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:
|
|
… I use something like this to extract what I want to tweet:
|
|
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.