Parsing JSON Web Tokens

Decoding a JWT with JQ

Published: Tuesday, Apr 13, 2021 Last modified: Wednesday, Sep 22, 2021

Using the example Bearer token from https://jwt.io/

Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
(ins)[hendry@t14s tmp]$ cat token2 | jq -R 'split(".") | .[0] | @base64d | fromjson'
{
  "alg": "HS256",
  "typ": "JWT"
}

Payload

(ins)[hendry@t14s tmp]$ cat token2 | jq -R 'split(".") | .[1] | @base64d | fromjson'
{
  "sub": "1234567890",
  "name": "John Doe",
  "iat": 1516239022
}