fzf and jq for fun and profit
I'm a casual vim user (mainly nvim these days). One plugin for vim I find essential is fzf to quickly find any file in my current project.
Recently, I was debugging a graphql query and I needed to search a JSON file for a snippet of text. Alas, the JSON was on a single line and on a remote server. After a quick search, I found this magic command line to format the JSON file and preview the result:
Recently, I was debugging a graphql query and I needed to search a JSON file for a snippet of text. Alas, the JSON was on a single line and on a remote server. After a quick search, I found this magic command line to format the JSON file and preview the result:
jq -C . data.json | less -R
This formats `data.json`, pipes the results to `less`, and interprets the escape sequences (from the colors) in "raw" form.
While this solve my problem in the short term, I realize that I don't use `jq` enough in my daily life. Also, I remember that this could be chained with `fzf` as a faster way to find the text I'm looking for.
After a few minutes of play, I added this function to my zsh config (`~/.zshrc`):
function jzf { # invoke as `jzf some-file.json` jq . $* | fzf }
While I lose access to color, I can now quickly find any snippet of text in a JSON file (and format a JSON file from the command line). 🚀