About the JSON to Base64
Encode JSON as a Base64 string for HTTP headers, URLs, tokens or environment variables. It handles Unicode correctly, and can produce URL-safe output.
Key features
- Encodes JSON as standard Base64 or URL-safe Base64URL
- Correct UTF-8 handling for emoji and non-Latin text
- Optional minification first for shorter output
- Validates the JSON before encoding
- Instant results as you type
- Runs locally; safe for secrets and tokens
Why encode JSON as Base64?
Base64 turns any data into a string made only of letters, digits and a couple of symbols. That makes JSON safe to place where special characters such as quotes, braces and line breaks would cause trouble:
- HTTP headers. Custom headers can't contain line breaks and often choke on quotes.
- URLs and query strings. Base64URL output can be dropped straight into a link.
- Environment variables. Store a JSON config in a single env var without escaping.
- Kubernetes secrets and CI/CD variables, which are commonly Base64-encoded.
- Tokens. JWT headers and payloads are Base64URL-encoded JSON.
- Data attributes and cookies, where quotes must be avoided.
Example
{"user":"ada","role":"admin"}
| Mode | Output |
|---|---|
| Standard Base64 | eyJ1c2VyIjoiYWRhIiwicm9sZSI6ImFkbWluIn0= |
| URL-safe Base64URL | eyJ1c2VyIjoiYWRhIiwicm9sZSI6ImFkbWluIn0 |
Standard vs. URL-safe
| Base64 | Base64URL | |
|---|---|---|
| Characters | A–Z a–z 0–9 + / | A–Z a–z 0–9 - _ |
| Padding | = at the end | Usually omitted |
| Use in URLs | Needs percent-encoding | Safe as-is |
| Used by | Email (MIME), data URIs, Kubernetes | JWT, OAuth, URL parameters |
Doing it in code
// Browser / Node.js (UTF-8 safe)
const b64 = btoa(String.fromCharCode(...new TextEncoder().encode(JSON.stringify(data))));
# Shell
echo -n '{"user":"ada"}' | base64
Important: Base64 is not security
Base64-encoded data looks scrambled but isn't protected: decoding takes milliseconds. Don't use it to hide passwords or API keys from users.
Related tools
Decode with Base64 to JSON. Inspect tokens with the JWT Decoder. Encode images with Image to Base64.
How to use the JSON to Base64
- Paste your data into the input box, upload a file, or click Sample to try it out.
- Adjust the options above the editor if you need to (indentation, delimiter, and so on).
- The Base64 appears instantly in the output panel. Any errors are shown with their line and column.
- Click Copy to copy the result, or Download to save it as a file.