How to Decode a JWT Token (Without the Secret)
JWTs are encoded, not encrypted β anyone can read the payload without the secret key. Decoding a JWT is essential for debugging authentication issues, inspecting token claims, and verifying that tokens contain the expected data. The secret is only needed to verify the signature, not to read the contents.
Decoding a JWT Manually
A signed JWT (the usual kind, a JWS in compact form) has three parts separated by dots: header, payload and signature. The first two are JSON encoded as Base64URL β Base64 with - and _ instead of + and /, and with the trailing = padding removed (RFC 7515). To read one:
1. Split the token at the dots. Three parts means a signed token; five parts means an encrypted token (JWE, RFC 7516), whose payload you cannot read without the key.
2. Base64URL-decode the header. It names the algorithm (alg), usually the type (typ) and often a key ID (kid).
3. Base64URL-decode the payload to get the claims.
4. Leave the signature alone: it is raw bytes, and it only means something when you check it with the right key.
Decoding in JavaScript (Correctly)
The one-liner that circulates β JSON.parse(atob(part.replace(/-/g, '+').replace(/_/g, '/'))) β works for plain ASCII claims and breaks on everything else, because atob() returns each byte as one character instead of decoding UTF-8. Decode the bytes as UTF-8 explicitly and restore the padding:
In Node.js, Buffer.from(part, 'base64url').toString('utf8') does the same in one call.
Worked Example: The Common One-Liner vs a UTF-8 Decoder
We built three test tokens and decoded the name claim with both functions (Node.js with browser atob semantics; script in our test folder, October 13, 2026):
| Claim in the token | atob one-liner | UTF-8 decoder above |
|---|---|---|
| Ana | Ana | Ana |
| JosΓ© MΓΌller | JosΓΒ© MΓΒΌller | JosΓ© MΓΌller |
| Rocket π | Rocket Γ° followed by three unprintable characters | Rocket π |
Any name, address or company claim outside ASCII is garbled by the one-liner. Our JWT Decoder had the same bug until October 2026; it now decodes UTF-8 and flags unsigned (alg: none) tokens and millisecond timestamps.
What to Look for in a Decoded JWT
The registered claims are defined in RFC 7519: iss (issuer), sub (subject, usually a user ID), aud (audience), exp (expiry), nbf (not valid before), iat (issued at) and jti (token ID). The three time claims are NumericDate values β seconds since 1970-01-01 UTC, not milliseconds β so a 13-digit exp is a bug in whatever issued the token. A token is usable only when the current time is at or after nbf and before exp; allow a small clock-skew margin of a minute or two, not hours.
Decoding vs Verifying
Decoding reads the claims; it proves nothing about them. Anyone can create a token with any payload. Before trusting one, verify it server-side with a maintained library, and follow the JWT Best Current Practices (RFC 8725): accept only the algorithms you expect instead of trusting the token's own alg header (which is how alg: none and RSA/HMAC key-confusion attacks work), check iss and aud, and validate exp and nbf. And remember that a signed JWT is readable by anyone who holds it β never put secrets or personal data in it that the holder should not see.
Frequently Asked Questions
Can I decode a JWT without the secret key?
How do I check if a JWT is expired?
Is it safe to decode JWTs in the browser?
- [1]IETF RFC 7519: JSON Web Token (registered claims; NumericDate) β
- [2]IETF RFC 7515: JSON Web Signature (compact serialization; Base64URL without padding) β
- [3]IETF RFC 7516: JSON Web Encryption (five-part compact form) β
- [4]IETF RFC 8725: JSON Web Token Best Current Practices β
- [5]MDN Web Docs: Window.atob() and the Unicode problem β
- [6]MDN Web Docs: TextDecoder β