Skip to content

Instantly share code, notes, and snippets.

@5kr1p7
Last active June 10, 2024 17:24
Show Gist options
  • Save 5kr1p7/d148fc198d3241ee79e364d168006feb to your computer and use it in GitHub Desktop.
Save 5kr1p7/d148fc198d3241ee79e364d168006feb to your computer and use it in GitHub Desktop.
Decode JWT to JSON

Decode JWT tokens with Bash

Need jq >=1.6

#!/bin/bash

function jwt_decode(){
    jq -R 'split(".") | .[1] | @base64d | fromjson' <<< "$1"
}

Usage:

jwt_decode eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
{
  "sub": "1234567890",
  "name": "John Doe",
  "iat": 1516239022
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment