DEV Community

IAMDevBox
IAMDevBox

Posted on

Decode JWT Tokens from the Command Line Like a Pro

JSON Web Tokens (JWTs) are a popular way to store and transmit data securely. But what happens when you need to inspect the contents of a JWT? In this tutorial, we'll explore how to decode JWTs from the command line using popular tools like jq and jwt.

To get started, you'll need a JWT token to work with. You can obtain one by logging into a service that uses JWT authentication, such as IAMDevBox.com. Once you have a token, you can use the jq command-line JSON processor to extract the contents.

For example, to extract the user's email address from a JWT token, you can use the following command:

jq -r '.email' your_jwt_token.json  
Enter fullscreen mode Exit fullscreen mode

This will output the value of the email field in the JWT token.

Next, let's use the jwt command-line tool to decode the entire JWT token:

jwt decode your_jwt_token  
Enter fullscreen mode Exit fullscreen mode

This will output the decoded JWT token in a human-readable format, including the claims and signature.

Read more: Decode JWT Tokens from the Command Line Like a Pro

Top comments (0)