JWT Decoder: how it works and how to build one
Decode a JSON Web Token and check when it expires. This guide explains what happens behind the button and shows the code, so you can build your own.
What it does
Paste a JWT to see its header and payload as formatted JSON, plus the issued-at, not-before and expiry times in your local time. The token is decoded in your browser and never sent anywhere.
When to use it
- Checking why an API says 401
- Seeing which claims a login provider sends
- Checking expiry times
How to use it
- Paste the token (the text with two dots).
- Read the header, payload and time claims.
- Copy either part as JSON.
Try it free in your browser, nothing is uploaded: https://eskillsfy.com/tools/jwt-decoder
How it works
A JWT is three Base64URL parts joined by dots: header, payload and signature. The first two are just JSON, so decoding is splitting on dots and Base64URL-decoding.
Decoding does not verify the token. Only the server that holds the secret or public key can check the signature. The tool reads the exp, iat and nbf claims (seconds since 1970) and shows them as dates.
Build it yourself
Here is the core of the tool. It has no dependencies unless noted, so you can paste it into any TypeScript or JavaScript project.
jwt.ts (ts)
const b64url = (s: string) => {
const b = s.replace(/-/g, "+").replace(/_/g, "/");
const bin = atob(b + "=".repeat((4 - (b.length % 4)) % 4));
return new TextDecoder().decode(Uint8Array.from(bin, (c) => c.charCodeAt(0)));
};
export function decodeJwt(token: string) {
const [h, p, sig] = token.trim().split(".");
if (!h || !p || sig === undefined) throw new Error("A JWT has three parts separated by dots");
const header = JSON.parse(b64url(h));
const payload = JSON.parse(b64url(p));
const exp = payload.exp ? new Date(payload.exp * 1000) : null;
return { header, payload, expires: exp, expired: exp ? exp < new Date() : false };
}
Make it production-ready
- Verify HS256 signatures with crypto.subtle when the user provides the secret.
- Show a countdown to expiry.
Questions
Does it verify the signature?
No. Verifying needs the secret or public key, which should stay on your server. This tool only decodes.
Is it safe to paste a production token?
It never leaves your browser, but treat live tokens like passwords and prefer expired ones when sharing screens.
Free, runs in your browser, nothing is uploaded.