JWT Encoder

Build and sign JSON Web Tokens with HMAC algorithms, privately in your browser.

JWT Encoder tool

Token

About the JWT Encoder

Testing an API that expects a bearer token, or learning how JSON Web Tokens are built, is easier when you can create one yourself. This JWT encoder takes a JSON header and payload, signs them with your secret using HS256, HS384 or HS512 and shows the finished token in its three colored parts, ready to paste into an Authorization header. Keep production secrets out of any website and use test keys for experiments.

Helper buttons add the standard time claims: iat, the time the token was issued, exp, when it expires, and nbf, when it becomes valid, all as Unix timestamps in seconds as the specification requires. The payload is validated as you type, so a missing quote or trailing comma is reported with its position before it turns into a broken token.

Secrets can be plain text or Base64-encoded, matching how frameworks store them. Use long, random secrets in production; short words can be guessed offline from any token. Tokens are built with your browser's Web Crypto and nothing is uploaded, which matters because a JWT secret can unlock a whole system.

To read the contents of an existing token, use the JWT decoder. For raw message signatures, try the HMAC generator, and to convert times for exp claims, the Unix timestamp converter. Everything updates live, so you can change a claim or the secret and immediately see how the encoded payload and the signature change.

How to use the JWT Encoder

  1. Choose the algorithmPick HS256, HS384 or HS512; the header updates to match.
  2. Write the payloadEdit the JSON claims, and use the buttons to add iat, exp or nbf.
  3. Enter the secretType the signing secret, and tick Base64 if your secret is stored that way.
  4. Copy the tokenThe signed token appears at once; copy it for your request or test.

JWT Encoder features

  • HS256, HS384 and HS512 signing
  • Editable header and payload JSON
  • iat, exp and nbf helpers
  • JSON errors with line and column
  • Plain text or Base64 secrets
  • Colored token parts
  • Uses the browser's Web Crypto
  • Nothing is uploaded

Common uses

  • Creating test tokens for APIs and microservices
  • Debugging authentication in development
  • Reproducing tokens from documentation examples
  • Generating short-lived tokens for internal tools
  • Teaching how JWT signing works

Creating JWTs in practice: test tokens for local APIs, negative tests, the milliseconds bug, separate secrets and claim design

By the FreeToolsWorld editorial team · Updated November 2026 · How we write and check our guides

Generating your own tokens is one of the fastest ways to test an API that uses JSON Web Tokens. Instead of logging in through a full sign-in flow, you create a token with exactly the claims a test needs. This guide builds a test token for a local API, shows how to test the cases where a token should be rejected, explains a widespread timestamp bug and covers secrets for different environments and sensible claim design.

A worked example: a test token for a local API

A developer building a blog API needs a token for an editor. With the header set to HS256 and the payload containing the subject 1042, the role editor, an issued-at time of 1792939560 and an expiry of 1792943160, signed with the development secret local-dev-secret-not-for-production, the token begins:

  • eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMDQyIiwicm9sZSI6ImVkaXRvciIs...

The two timestamps are 25 October 2026 at 14:46 and 15:46 UTC, giving one hour of validity. The token is then sent with a request such as curl -H "Authorization: Bearer <token>" http://localhost:3000/api/posts, replacing the placeholder with the full token.

Testing the rejections

An API that accepts good tokens is only half tested. Create tokens that should fail and confirm each is rejected: one whose expiry has passed, one signed with a different secret, one with the wrong audience, one missing a required claim and one with a role that lacks permission. Each should return a clear error, usually 401 for invalid tokens and 403 for valid tokens without permission.

The milliseconds bug

JWT times are in seconds, but JavaScript's Date.now() returns milliseconds. Code that sets the expiry to Date.now() + 3600 creates a token that expires in roughly the year 58,000, effectively never. The reverse mistake, an issued-at time in milliseconds, may make some libraries reject the token as issued in the future. Divide by 1,000 and round down before using JavaScript times in claims.

Separate secrets for each environment

Development, staging and production should each use a different secret. Then a test token created on a laptop, or leaked from a staging log, cannot unlock production. Production secrets should be long and random, stored in environment variables or a secrets manager, and never committed to code or pasted into shared documents.

When a shared secret is the wrong design

With HS256, every service that verifies tokens holds the same secret and could therefore create tokens too. In systems with many services, or where third parties verify tokens, signing with a private key using algorithms such as RS256 or ES256 is safer: only the sign-in service holds the private key, and everyone else verifies with the public key.

Designing claims

Use a stable user ID for the subject rather than an email address, because emails change. Include an issuer and an audience so tokens cannot be reused at the wrong service. Keep payloads small, since tokens travel with every request. Remember that anyone holding a token can read its payload, so leave out personal and sensitive data.

Rotating secrets with key IDs

Adding a kid value to the header, naming which key signed the token, makes rotation smoother. During a changeover, the server accepts tokens signed with either the old or the new key, choosing by kid, until all old tokens have expired. Without key IDs, changing the secret logs out every user at once.

Common mistakes

  • Setting exp from JavaScript milliseconds.
  • Reusing one secret across development and production.
  • Testing only that valid tokens are accepted.
  • Putting email addresses or personal data in the payload.

Related tools

To pick expiry times, use Unix Timestamp Generator. To create a strong secret, try Password Generator, and to encode a secret in Base64, Base64 Encoder.

Using tokens in API tools

API clients such as Postman and Insomnia have a Bearer token option where a generated token can be pasted. Storing a token per environment as a variable lets you switch between development and staging with one click. Generating fresh tokens with different roles makes it quick to check what each type of user can see and do.

Scheduled access with nbf

The not-before claim makes a token valid only from a certain time, which suits cases such as an online exam that opens at 10 am. Create a test token with nbf set a few minutes ahead and confirm the API rejects it until that time passes, then accepts it afterwards. This tests both the claim and the server's clock.

Token lifetimes

Production systems usually issue short-lived access tokens, often valid for between five and fifteen minutes, together with longer-lived refresh tokens that can be revoked. For local testing, a longer lifetime saves repeated token creation, but keep long-lived tokens strictly to development secrets so they are worthless anywhere else.

Privacy

Tokens are created with your browser's Web Crypto. Secrets and payloads are not uploaded, but use development secrets rather than production ones whenever possible.

Frequently asked questions

What is a JWT?

A JSON Web Token is a compact, signed way to pass claims between systems. It has three Base64URL parts separated by dots: a header describing the algorithm, a payload with the claims, and a signature that proves the token was issued by someone who knows the secret.

Is the payload of a JWT encrypted?

No. The header and payload are only encoded, so anyone with the token can read them with a decoder. Never put passwords or secrets in a JWT payload; the signature only protects against changes.

What do iat, exp and nbf mean?

iat is when the token was issued, exp is when it expires and nbf is the time before which it must not be accepted. All three are Unix timestamps in seconds, which the helper buttons insert for you.

Which algorithm should I choose?

HS256 is the most widely supported and secure with a strong secret. HS384 and HS512 use longer hashes. For tokens that many services must verify without sharing a secret, use RS256 or ES256 with a key pair, which needs a server-side library.

How long should my secret be?

At least 32 random bytes for HS256, and longer for HS384 and HS512. Short or dictionary-word secrets can be brute-forced offline from a single captured token.

Why does my token differ from another tool's?

Whitespace and key order in the header and payload change the encoded parts and the signature. This tool encodes your JSON compactly in the order you wrote it, which matches most libraries.

Is my secret uploaded?

No. Everything is calculated by code running in this page on your own device. Your text, files and keys are never uploaded, stored or logged, so it is safe to use with private data.

Can I verify a token here?

Yes, indirectly. Enter the same header and payload, type the secret, and compare the signature part with the token you have. If the third part matches exactly, the token was signed with that secret.