How to Decode JWT Token: Read Header and Payload Safely
JSON Web Tokens (JWTs) are everywhere in modern apps, carrying login sessions and API permissions between systems. If you’re debugging an API or checking why a login fails, knowing how to decode JWT token data lets you r
JSON Web Tokens (JWTs) are everywhere in modern apps, carrying login sessions and API permissions between systems. If you’re debugging an API or checking why a login fails, knowing how to decode JWT token data lets you read exactly what’s inside in seconds.
This guide covers the structure of a JWT, how to decode JWT token contents online or in code, and the one thing decoding can’t tell you.
Quick answer: Paste the token into a free JWT decoder to see its header and payload as readable JSON, including when it expires. Decoding is just Base64URL, so anyone can read a JWT’s contents without a key. It doesn’t prove the token is genuine: only signature verification with the right secret or public key does that.
What’s inside a JWT?
A JWT has three parts separated by dots: header.payload.signature. The first two parts are JSON, encoded with Base64URL.
| Part | Contains | Example |
|---|---|---|
| Header | Signing algorithm and token type | {“alg”:”HS256″,”typ”:”JWT”} |
| Payload | Claims about the user and the token | {“sub”:”1234″,”exp”:1798761600} |
| Signature | Proof the token wasn’t changed | Made with a secret or private key |
Common payload claims include iss (issuer), sub (subject, often the user ID), aud (audience), exp (expiry), iat (issued at) and nbf (not before). Times are Unix timestamps in seconds, so exp 1798761600 means 1 January 2027, 00:00 UTC.
How to decode JWT token online
- Open the decoder. Go to the free JWT Decoder.
- Copy your token. For example, from the Authorization: Bearer header in your browser’s DevTools Network tab, or from your app’s logs.
- Paste it. Put it in the JWT box.
- Read the result. The Header and Payload appear as readable JSON.
- Check the expiry. The decoder shows when the token expires or whether it has already expired.
Decoding happens entirely in your browser, so the token isn’t sent anywhere. Still, as a habit, avoid pasting production tokens into any third-party tool. Use test tokens where you can, because a valid token works like a temporary password.
How to decode a JWT in code
JavaScript (browser):
const part = token.split('.')[1].replace(/-/g, '+').replace(/_/g, '/');
const payload = JSON.parse(atob(part));
Node.js:
const payload = JSON.parse(Buffer.from(token.split('.')[1], 'base64url').toString());
Python:
import base64, json
part = token.split('.')[1]
part += '=' * (-len(part) % 4)
print(json.loads(base64.urlsafe_b64decode(part)))
The short browser version suits plain ASCII payloads. If names contain non-English characters, decode the bytes as UTF-8. To read a long payload comfortably, paste it into the JSON Formatter.
Decoding vs verifying
| Decoding | Verifying | |
|---|---|---|
| What it does | Reads the header and payload | Checks the signature |
| Needs a key? | No | Yes, the secret or public key |
| Proves the token is genuine? | No | Yes |
| When to use it | Debugging | On your server, before trusting any token |
Knowing how to decode JWT token data is great for debugging, but never trust a decoded payload on your server without verifying the signature with a proper library. Anyone can create a token with any payload. Only the signature shows it came from your auth server.
Problems you can spot by decoding
- Expired token: exp is in the past, so the server rejects it.
- Wrong audience: aud doesn’t match the API you’re calling.
- Missing permissions: the roles or scopes you expected aren’t in the payload.
- Unexpected algorithm: the header shows a different alg from the one your server expects.
- Not a JWT at all: some tokens are random strings that can’t be decoded.
Security tips
- Never put sensitive data in the payload. Anyone holding the token can read it.
- Keep access tokens short-lived and refresh them.
- Always send tokens over HTTPS.
- Treat tokens like passwords in logs, screenshots and support tickets.
Example: debugging a 401 error
Your app’s API calls suddenly return 401 Unauthorized. Copy the token from the request’s Authorization header and decode it. The payload shows an exp time from an hour ago, so the token expired and the app didn’t refresh it. Now you know to fix the refresh logic, not the API. Learning how to decode JWT token data is one of the fastest debugging habits a web developer can build.
Frequently asked questions
Does decoding verify the signature?
No. Verification needs the secret or public key used to sign the token, which the decoder never asks for. It only reads the header and payload, which anyone can do.
Is it safe to use with real tokens?
Decoding runs in your browser and the token isn’t sent anywhere. As a general habit, still avoid pasting production tokens into third-party tools.
Can I edit a JWT after decoding it?
You can change the text, but the signature won’t match any more, so a properly configured server will reject it.
Why is exp a big number?
It’s Unix time in seconds. The decoder turns it into a readable date for you.
Is a JWT encrypted?
A normal signed JWT is only encoded, not encrypted. Encrypted tokens (JWE) exist, but they have five parts instead of three.
Need to see what’s inside a token? Paste it into the free JWT Decoder and read the header and payload instantly.
This guide was first published on ToolKitFree, where you can use the free tool online.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.