CodeFaster

CodeFaster

Unix 1-liner using jq

Tyler Adams's avatar
Tyler Adams
Jul 20, 2023
∙ Paid
3
Share

Recently, I needed to get all tokens for accounts that were PENDING_REVIEW in a system, here’s how to do it in a unix 1 liner.

./get-all-accounts | jq .data | map(select(.status == "PENDING_REVIEW")) | map(.token) | .[] -r | pbcopy

First, write a small script to get all accounts and output as json. In this case it’s a curl, but if it was a paginating API, we’d want to handle that inside the first step. We’ll call it get-all-accounts.

Thanks for reading CodeFaster! Subscribe for free to receive new posts and support my work.

The JSON response is then piped into jq, a command-line JSON processor.

The command is broken down into four transformations:

  1. .data: This takes the “data” property of the root object.

Output after this stage looks like this:

    [
      {
        "created": "2023-08-09T13:21:17.112064",
        "email": "balancing+kyc+readonly@paymentcorp.com",
        "status": "APPROVED",
        "token": "7db20fa2-cb36-403f-d551-1585730b42f8"
      },
      ...
    ]

  1. map(select(.stat…

This post is for paid subscribers

Already a paid subscriber? Sign in
© 2025 Tyler Adams
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture