#!/usr/bin/env zsh set -euo pipefail usage="usage: `basename $ZSH_ARGZERO` token" function pretty_json { [ $# -ge 1 ] && str=$1 || str=$(<&0) # could read a JSON_PRETTY_PRINTER env variable in case of fancy stuff like `echo $str | underscore print --color` # but we leave this as an exercise to the reader if command -v jq &>/dev/null; then print $str | jq --color-output \ || print $str elif python -m json.tool -h &>/dev/null; then print $str | python -m json.tool \ || print $str else print $str fi } [ $# -ne 1 ] && print $usage >&2 && exit 1 [ $1 = "-h" ] && print $usage && exit 0 IFS='.' read header payload signature <<<$1 echo $payload | sed "s/_/\//g" | sed "s/-/+/g" | base64 -d | pretty_json