JWT decoder

Paste a JSON Web Token to see its header, payload and expiry. Your token stays in your browser.

Header
Payload

This tool runs in your browser. We never send what you type or paste to a server.

How a JWT is built

A JWT has three parts separated by dots: header.payload.signature. The header and payload are URL-safe Base64-encoded JSON, which is why anyone can read them. The signature proves the token wasn't changed, but checking it needs the secret or public key, which this tool doesn't ask for.

Standard claims

  • iss: issuer · sub: subject (usually the user ID) · aud: audience
  • exp: expiry time · nbf: not valid before · iat: issued at (all Unix seconds)
  • jti: a unique token ID

Never put secrets in a JWT payload: it's encoded, not encrypted.

Example

A token is three Base64url parts separated by dots: header, payload and signature.

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI0MiIsIm5hbWUiOiJBbmEgU2lsdmEiLCJpYXQiOjE3MDAwMDAwMDAsImV4cCI6MTcwMDAwMzYwMH0.<signature>

The first two parts decode to:

{"alg": "HS256", "typ": "JWT"}
{"sub": "42", "name": "Ana Silva", "iat": 1700000000, "exp": 1700003600}

iat and exp are Unix timestamps: this token was issued at 22:13 UTC on 14 November 2023 and expired an hour later.

Decoding a JWT in code

Decoding needs no library: split on the dots, Base64url-decode the first two parts and parse them as JSON. The examples use this test token, signed with HS256 and the secret my-secret:

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI0MiIsIm5hbWUiOiJKb3PDqSIsImlhdCI6MTcwMDAwMDAwMCwiZXhwIjoxNzAwMDAzNjAwfQ.k3WEcalC4rkcG-ViKYW0poAucmoOwJqH_Xf1PhsgWtY

In the browser, swap the URL-safe characters back and decode the bytes as UTF-8. atob tolerates the missing padding:

function decodeJwtPart(part) {
  const b64 = part.replace(/-/g, '+').replace(/_/g, '/');
  const bytes = Uint8Array.from(atob(b64), (c) => c.charCodeAt(0));
  return JSON.parse(new TextDecoder().decode(bytes));   // the JSON is UTF-8
}
const [header, payload] = token.split('.').slice(0, 2).map(decodeJwtPart);
console.log(header.alg);                                // → HS256
console.log(payload.name);                              // → José
console.log(new Date(payload.exp * 1000).toISOString()); // → 2023-11-14T23:13:20.000Z   exp is in seconds

The popular one-liner JSON.parse(atob(part)) works until a claim contains a non-ASCII character, then shows mojibake, and it throws on any part that contains - or _:

console.log(JSON.parse(atob(token.split('.')[1])).name);   // → José   UTF-8 bytes read as Latin-1

Node reads Base64url directly; in Python, put the padding back first:

const claims = JSON.parse(Buffer.from(token.split('.')[1], 'base64url').toString('utf8'));
console.log(claims.sub, claims.name);                   // → 42 José
import base64, json
from datetime import datetime, timezone

def decode_part(part):
    return json.loads(base64.urlsafe_b64decode(part + '=' * (-len(part) % 4)))

header, payload = (decode_part(p) for p in token.split('.')[:2])
print(header)                                                  # → {'alg': 'HS256', 'typ': 'JWT'}
print(payload['name'], payload['exp'])                         # → José 1700003600
print(datetime.fromtimestamp(payload['exp'], tz=timezone.utc)) # → 2023-11-14 23:13:20+00:00

From a shell, take the second field and restore the padding before decoding:

part=$(printf '%s' "$token" | cut -d. -f2)
while [ $(( ${#part} % 4 )) -ne 0 ]; do part="$part="; done   # restore the padding
printf '%s' "$part" | basenc --base64url -d; echo                 # → {"sub":"42","name":"José","iat":1700000000,"exp":1700003600}
printf '%s' "$part" | tr '_-' '/+' | base64 -d; echo              # → {"sub":"42","name":"José","iat":1700000000,"exp":1700003600}

How the signature is made and checked

For HS256 the signature is an HMAC-SHA256 of the exact text header.payload (the two Base64url strings joined by a dot) using a shared secret, itself Base64url-encoded. Change one character of the payload and the signature no longer matches. Recomputing it shows the idea:

const [h, p, sig] = token.split('.');
const expected = createHmac('sha256', 'my-secret').update(`${h}.${p}`).digest('base64url');
console.log(expected);                                  // → k3WEcalC4rkcG-ViKYW0poAucmoOwJqH_Xf1PhsgWtY
console.log(expected.length === sig.length && timingSafeEqual(Buffer.from(expected), Buffer.from(sig)));   // → true

RS256, PS256 and ES256 sign with a private key instead, so anyone with the public key, often published at a JWKS URL, can verify but not create tokens. In real code, use a maintained library and tell it which algorithms you accept; never take the algorithm from the token's own header. That closes the old alg: none and RSA/HMAC key-confusion holes. Library calls, not run here:

# Python, PyJWT
claims = jwt.decode(token, 'my-secret', algorithms=['HS256'], audience='my-api')

// JavaScript, jose
const { payload } = await jwtVerify(token, new TextEncoder().encode('my-secret'), { algorithms: ['HS256'] });

A verifier should also check exp, nbf, iss and aud, allowing a small leeway (a minute or so) for clock differences between servers. The rules are in RFC 7519 (JWT) and RFC 8725 (best practices).

Things that trip people up

  • Seconds, not milliseconds. exp, iat and nbf are Unix seconds. JavaScript's Date.now() is milliseconds, so compare with payload.exp * 1000. A token that seems to expire in the year 55,000 was made with milliseconds.
  • The Bearer prefix. Tokens copied from an Authorization header start with Bearer . This tool strips it; your own code may need to.
  • Five parts. A token with five dot-separated parts is an encrypted JWE. Its payload cannot be read without the key, and this tool says so rather than showing nonsense.
  • Tokens in URLs and logs. A JWT is a bearer credential: whoever holds it can use it until it expires. Keep tokens out of query strings, analytics and error reports.
  • Logging out. A signed JWT stays valid until exp even after the user logs out. Keep lifetimes short, or keep a server-side deny list of jti values.

The decoded times above are shown in your browser's time zone; the Unix timestamp converter shows them in UTC and other zones.

Questions

Is it safe to paste my token here?

The token is decoded in your browser and never sent anywhere. Even so, treat live tokens like passwords and prefer expired or test tokens.

Does this verify the signature?

No. It only decodes. Verify signatures on your server with your secret or public key.

How do I decode a JWT in JavaScript without a library?

Take the second dot-separated part, replace - with + and _ with /, decode it with atob, turn the result into bytes and decode them with TextDecoder, then JSON.parse the text. In Node, JSON.parse(Buffer.from(part, 'base64url').toString()) does the same.

Why does my decoded JWT show strange characters like é?

The payload is UTF-8, but atob returns one character per byte, as if it were Latin-1. Decode the bytes with TextDecoder (or Buffer in Node) before parsing the JSON.

What does alg none mean in a JWT header?

An unsecured token with no signature. Servers should reject it unless they have deliberately allowed it, which almost none should. Configure your JWT library with an explicit list of accepted algorithms.

Can I change the payload and keep using the token?

You can edit it, but the signature will no longer match, so a server that verifies tokens rejects it. Only the holder of the secret or private key can make a valid new token.