JWT Decoder

Security

Decode and inspect JWT tokens without verification. Check expiry and claims.

Import

Import
import { jwt } from 'toolmetry';

API Reference

FunctionParametersReturnsDescription
jwt.decodetoken: string{ header, payload, signature }Decode a JWT into its parts
jwt.decodeHeadertoken: stringobjectDecode only the header
jwt.decodePayloadtoken: stringobjectDecode only the payload
jwt.isExpiredtoken: string, graceSeconds?: numberbooleanCheck if a JWT is expired
jwt.isValidFormattoken: stringbooleanValidate JWT format
jwt.getAlgorithmtoken: stringstring | nullGet the algorithm from JWT header
jwt.timeUntilExpirytoken: stringnumber | nullSeconds until JWT expires

Examples

Decode a JWT
import { jwt } from 'toolmetry';

const token = 'eyJhbGciOiJIUzI1NiIs...';

const { header, payload, signature } = jwt.decode(token);
// header: { alg: "HS256", typ: "JWT" }
// payload: { sub: "1234567890", name: "John", ... }
Check Expiry
import { jwt } from 'toolmetry';

const expired = jwt.isExpired(token); // true/false
const timeLeft = jwt.timeUntilExpiry(token); // seconds or null
Get Algorithm
import { jwt } from 'toolmetry';

const algo = jwt.getAlgorithm(token);
// "HS256"

Try It Live