There are plenty of tools and libraries out there to decode (and verify) JSON Web Tokens (JWT). But what if you are in a context where you can not or don't want to use these?

Here is a simple command line one-liner to decode a JWT passed through standard input, using Python and just some standard library modules:

python -c 'import base64,json,sys,pprint;pprint.pprint([json.loads(base64.urlsafe_b64decode(p+"===")) for p in sys.stdin.read().strip().split(".")[:2]])'

⚠️ Important note: there is no JWT signature verification whatsoever here. Just use this for quick-and-dirty payload inspection and debugging purposes. Don't blindly trust the output.

See it in action on a dummy JWT:

$> echo 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.Meh' \
    | python -c 'import base64,json,sys,pprint;pprint.pprint([json.loads(base64.urlsafe_b64decode(p+"===")) for p in sys.stdin.read().strip().split(".")[:2]])'

[{'alg': 'HS256', 'typ': 'JWT'},
 {'iat': 1516239022, 'name': 'John Doe', 'sub': '1234567890'}]