fzf, jq, pipes for Fun Command Line Text Processing
Do you ever get a wall of JSON in your commandline and not sure where to go next? Especially if you’re looking for a particular value or a few of them?
Here’s 3 tools to help out of this mess:
- jq - jq is a lightweight and flexible command-line JSON processor
- fzf - a commandline fuzzy finder
- Pipe operator “|”
The core utility here is jq, which helps you process JSON right from your terminal like a pro. You can immediately start by passing it to JQ using the pipe operator as so:
curl https://dummyjson.com/users | jq
Depending on your terminal setup, you should see code highlighting instantly and some prettier formatting!
The fun does not end here. jq has a way to query the JSON object. Since the users are stored in the users
array, I can access the users array and pull out just the firstName
as so:
curl https://dummyjson.com/users | jq ".users.[].firstName"
There’s plenty of additional querying options that you can read in their documentation. The best part is now you can pass it to the fuzzy finder and search for any text.
curl https://dummyjson.com/users | jq ".users.[].firstName" | fzf
As you can see, the pipe operator helps us pass the output between each utility (curl, jq and fzf). Hopefully you get some mileage out of this!