How to use the linux command line json parser (jq) to extract a specific value?

I’m running this command line json parser (jq) in Debian GNU/Linux 11 (bullseye) to decode the json data:

jq -R ‘split(".") | .[0],.[1] | @base64d | fromjson’ <<<

  "alg": "HS256",
  "typ": "JWT"
  "sub": "1234567890",
  "name": "John Doe",
  "iat": 1516239022,
  "exp": 1655384832

Instead of returning ALL key/value pairs, is there a way to modify that command to extract only the expiration date 1655384832 value?

>Solution :

You don’t need the first object, you can ignore it (remove [0]). Then just specify which key you want:

jq -R 'split(".") | .[1] | @base64d | fromjson | .exp' <<< ...

Leave a Reply