Blog
Using Flox and jless to automate all kinds of tasks
Michael Stahnke | 27 September 2024
Fun Package Fridays is a series where we ask members of the Flox team to share fun and perhaps not-so-well-known tools and utilities you can find in the Flox Catalog, powered by Nix. Today's edition come from Michael Stahnke, our head of engineering.
This is a new series for us! To kick things off, I wanted to share a tool I only recently discovered. Jless is a terminal pager in the spirit of more
or less
, but specifically designed for JSON documents. It pretty-formats the JSON, which makes it much more readable, but my favorite feature is that it also displays the jq
filter for highlighted items.
This filter gives you a way to reference that specific part of the JSON structure using jq
syntax. It’s a big time-saver when you’re looking for some quick automation, and it’s just generally helpful.
You can check it out yourself by flox install
-ing it. You might also want jq
, along with curl
, just in case. No problem! You can get all of these (and much more) from the Flox Catalog:
Speaking of curl
, let’s use it to fetch a list of public repos from GitHub and then pipe the output to jless
, which automatically formats the raw JSON into a prettified, readable format.
As you can see, the view with jless
is just much more intuitive and easier to navigate than with the raw JSON. Plus, jless
lets you interact with the JSON data structures, scrolling through them and optionally expanding or collapsing nested objects.
In the above screenshot, I’ve highlighted the downloads_url
of the Thin project, so jless shows me the jq
filter string in the bottom highlight bar. With that filter string, I can easily extract, manipulate, or query specific parts of the JSON data. For example, if I wanted to do something with automation, I might:
Or how about this example, which fetches data from NASA's “Astronomy Picture of the Day” API, downloads the corresponding image, and embeds the image's title and description as Exif metadata. This script depends on exiftool
, which you can easily install via the Flox Catalog.
You can automate this by embedding it in the [hook]
section of manifest.toml
, the setup file that defines a Flox environment. Running flox activate
triggers the bash logic, opening the NASA JSON data in jless and giving you the option to save the image. Just alias flox activate
to a command—say, nasa-foo
—and run it when you want to!
That’s a quick tour of jless
. Happy hacking!