qjp - turn any json file into a quick TUI menu
23 points by pm
23 points by pm
Hi lobsters!
Here's a quick example ilustrating what this does. A very quick way of checking the news on lobsters:
curl -s "https://lobste.rs/hottest.json" | qjp -d title -o url | xargs lynx
I threw this together to scratch my own itch. Perhaps others will find it useful too.
Nice work! I've a similar collection of scripts you might find useful. Admittedly I've not done a good job of publishing the source for reusability but you can see them here: https://codeberg.org/awal/quickactions.
The json_menu script reads json data from stdin, and presents a menu containing the passed data. Selected data is printed to stdout.
How the data is read and presented can be customized quickly with arguments passed as python expressions. Example:
$ echo '{"products":[{"id":1,"brand":"Lorem","title":"Ipsum..."}]}' \
| json_menu choices=it.products \
formatter='f"#{it.id} #{it.brand} - #{it.title}"' \
value=it.id
I like these small tools. I always wished fzf supported JSON input "natively" — I think fzf can function as qjp but you'd need to encode the input in some form (with jq probably) before pipeline to fzf.
That is exactly what I did all the time. I got tired of doing it for the 1000th time, so i decided to put this together.
In the process of writing this, I already learned that it can be useful for other things:
I will add jq syntax support to both the input and the output.
For comparison here is the hottest.json example with fzf:
curl -s "https://lobste.rs/hottest.json" |
jq -r '.[]|[.title,.url]|@tsv' |
fzf -d\\t --with-nth 1 --accept-nth=2 | xargs lynx
The trade-off is simpler and easier to type command line for simple cases vs all the extra features of fzf. Fuzzy search and Emacs-style navigation keys are the big ones for me.