Skip to content

Instantly share code, notes, and snippets.

@Gerg
Last active September 30, 2025 18:37
Show Gist options
  • Select an option

  • Save Gerg/0e99c1153e34615b1226b85506e505c9 to your computer and use it in GitHub Desktop.

Select an option

Save Gerg/0e99c1153e34615b1226b85506e505c9 to your computer and use it in GitHub Desktop.
JWT decode shell function
# Adapted from https://www.pgrs.net/2022/06/02/simple-command-line-function-to-decode-jwts/
jwt() {
if [ "$#" -gt 0 ]; then
printf %s "$@" | sed 's/[Bb]earer //' | jq -R 'split(".") |.[0:2] | map(gsub("-"; "+") | gsub("_"; "/") | gsub("%3D"; "=") | @base64d) | map(fromjson)' <<< $1
else
sed 's/[Bb]earer //' | jq -R 'split(".") |.[0:2] | map(gsub("-"; "+") | gsub("_"; "/") | gsub("%3D"; "=") | @base64d) | map(fromjson)'
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment