A JWT decoder can help you inspect a token quickly, but decoding is only the first step. This guide explains how to read JWT headers and claims, check time and audience values, verify signatures safely, diagnose common authentication failures, and use online JWT tools without exposing sensitive credentials.
Overview
JSON Web Tokens, or JWTs, are compact strings commonly used to carry authentication and authorization data between systems. A token usually has three dot-separated parts:
header.payload.signature
The header describes the token type and signing algorithm. The payload contains claims such as an issuer, subject, audience, expiration time, or application-specific role. The signature allows a verifier to check whether the signed content matches the expected key and algorithm.
A JWT is encoded, not automatically encrypted. Anyone who obtains a token can often decode its header and payload, so tokens should not contain passwords, private keys, payment details, or other confidential values unless an additional encryption design is being used. Decoding also does not prove that a token is authentic. A JWT decoder reads the visible structure; a JWT validator checks whether the token is acceptable for a particular application.
This distinction is central when learning how to decode a JWT token. Use decoding to understand what an API received. Use validation to decide whether your application should trust it.
For related JSON cleanup and inspection techniques, see the JSON Formatter and Validator Guide. A readable payload makes missing fields, incorrect types, and unexpected values easier to spot.
Core framework
1. Decode the three segments
JWT header and payload segments use base64url encoding. Base64url is an encoding format, not encryption, and it differs slightly from standard Base64 by using URL-safe characters. A decoder should split the token on periods, decode the first two segments, and parse the results as JSON. The signature segment is binary data represented in an encoded form; displaying it does not verify it.
A valid-looking payload may resemble this:
{
"iss": "https://auth.example.test",
"sub": "user-123",
"aud": "orders-api",
"exp": 1760000000,
"scope": "orders:read"
}
The values above are illustrative. The important point is that claim names and meanings depend on the issuing and consuming systems. Do not assume that a claim such as role or scope has authority merely because it appears in a decoded payload.
2. Interpret claims in context
Common registered claims include:
iss: the issuer that created the token.sub: the subject, often a user or service identifier.aud: the intended audience or API.exp: the expiration time, normally represented as a Unix timestamp.nbf: the time before which the token should not be accepted.iat: the time at which the token was issued.jti: a token identifier, when the system uses one.
Check whether timestamps are in seconds or another format before comparing them. Also account for a small, deliberately configured clock tolerance where appropriate; avoid treating a large time difference as a harmless clock problem. The expected issuer and audience should come from your application configuration, not from the token itself.
3. Verify the signature and algorithm
Signature verification requires the correct cryptographic algorithm and key. Symmetric algorithms use a shared secret, while asymmetric algorithms use a private key to sign and a corresponding public key to verify. The verifier should allow only the algorithms explicitly configured for that token issuer and endpoint.
Do not select a verification method simply because the token header advertises it. The header is untrusted input. A robust validator obtains the expected algorithm and key from trusted configuration or an appropriately verified key-discovery process, then rejects unexpected algorithms, malformed keys, and invalid signatures.
Signature verification is necessary but not sufficient. A token with a valid signature can still be expired, intended for another audience, issued by the wrong authority, or missing a required scope. Treat validation as a set of checks rather than a single pass or fail operation.
Practical examples
Inspecting a token in JavaScript
For local debugging, you can inspect the non-signature portions of a JWT without treating them as trusted authorization data:
function decodeJwtPart(part) {
const base64 = part.replace(/-/g, "+").replace(/_/g, "/");
const padded = base64.padEnd(Math.ceil(base64.length / 4) * 4, "=");
const bytes = Uint8Array.from(atob(padded), char => char.charCodeAt(0));
return JSON.parse(new TextDecoder().decode(bytes));
}
function inspectJwt(token) {
const parts = token.split(".");
if (parts.length !== 3) throw new Error("Expected three JWT segments");
return {
header: decodeJwtPart(parts[0]),
payload: decodeJwtPart(parts[1])
};
}
This browser-oriented example is an inspection helper, not a validator. It does not verify the signature, check the issuer, enforce the audience, or decide whether the token may access a resource. In a server application, use a maintained JWT library and configure its verification options explicitly rather than copying a decoder into an authorization path.
Diagnosing an API authentication failure
- Confirm that the request sends the expected authorization scheme and token location.
- Decode the header and payload locally to check for obvious formatting or claim problems.
- Compare
isswith the issuer configured for the API. - Compare
audwith the exact audience expected by the receiving service. - Convert
exp,nbf, andiatinto readable times and check the system clock. - Confirm that the verifier has the correct key and allows the issuer’s configured algorithm.
- Check required scopes or permissions separately from token validity.
If the failure occurs in a browser-based integration, authentication may be only one part of the problem. Request headers, preflight behavior, and server responses can also matter. The JavaScript Fetch API Error Handling guide and CORS Error Fix Guide provide useful adjacent debugging steps.
Using an online JWT tool safely
An online JWT decoder can be convenient for a deliberately fabricated token or non-sensitive test data. Avoid pasting production access tokens, refresh tokens, session tokens, or tokens belonging to another person into a third-party service. Even if a tool claims to process data in a particular way, a safer default is to inspect sensitive values locally or in an approved internal utility.
Before sharing a decoded payload in a bug report, remove identifiers, email addresses, scopes, tenant names, and timestamps that could reveal system details. A redacted example is usually enough to discuss a claim-format problem.
Common mistakes
- Confusing decoding with verification: Readable claims are not evidence that a token was issued by a trusted authority.
- Trusting client-side checks: Browser code can help display diagnostics, but authorization decisions belong in the protected service.
- Ignoring the audience: A token valid for one API may not be valid for another service.
- Checking only expiration: An unexpired token can still have the wrong issuer, audience, signature, or permissions.
- Accepting any algorithm: Restrict algorithms in server-side configuration and reject unexpected values.
- Using the wrong key: Key rotation, environment mix-ups, and issuer configuration errors commonly produce signature failures.
- Logging complete tokens: Authorization headers and token strings should be treated as sensitive debugging data. Log a request identifier and selected, redacted diagnostics instead.
- Assuming every JWT is an access token: Identity tokens, access tokens, and application-specific tokens may have different audiences and validation rules.
For complete API troubleshooting, combine token inspection with request tracing and structured server-side errors. The JavaScript API Integration Guide covers authentication, retries, and response handling in that wider workflow.
When to revisit
Return to this guide whenever the token issuer, identity provider, API audience, signing algorithm, or key-distribution method changes. A key rotation may require configuration updates even when application code remains the same. Changes to scopes, claim names, token lifetimes, clock settings, or gateway behavior can also alter validation results.
Make JWT debugging part of a repeatable development workflow:
- Create a non-production test token or use a safe fixture with no real credentials.
- Record the expected issuer, audience, algorithm, required claims, and permission rules for the endpoint.
- Decode the token only to inspect structure and values.
- Run the same validation path used by the service, including signature, issuer, audience, time, and permission checks.
- Test failure cases such as an expired token, wrong audience, altered payload, missing scope, and unknown key.
- Review logs to ensure they identify the failure without exposing the complete token.
Keep this checklist near your API integration tests and update it when authentication standards or library configuration options change. For a broader reference to encoding, JSON, and JWT utilities, see the Developer Utility Toolkit. Used carefully, a JWT decoder is a valuable developer tool; used as a substitute for validation, it can create a misleading sense of security.