When an API token stops working, I want to see what’s inside it, especially the expiry time. A JWT is three base64 parts separated by dots, and jq can decode the middle one.
echo "$TOKEN" | jq -R 'split(".")[1] | gsub("-";"+") | gsub("_";"/") | @base64d | fromjson'
echo "$TOKEN" | jq -R 'split(".")[1] | gsub("-";"+") | gsub("_";"/") | @base64d | fromjson | .exp | todate'
# "2026-01-01T00:00:00Z"
-R reads the token as a plain string, split(".")[1] takes the payload part, @base64d decodes it and fromjson parses the result. The second line goes one step further and turns the exp claim, a Unix timestamp, into a readable date with todate.
The two gsub calls are there because JWTs use the URL safe base64 alphabet, with - and _ instead of + and /. jq’s decoder expects the standard alphabet and errors out with “is not valid base64 data” on a token that happens to contain one of those characters. The missing = padding at the end is no problem.
This only reads the token. It doesn’t check the signature, so it tells you nothing about whether the token is genuine. And a token is a password while it’s valid, so I’d paste it into a terminal and never into a random website that offers to decode it.
Further reading: jq manual: @base64d, RFC 7519 (JWT)