Convert JSON to Base64
Encode JSON to Base64 or decode back. Standard / URL-safe / no padding. Pretty/minified/sorted. UTF-8 safe. Free, offline, client-side.
Encode JSON to Base64 (RFC 4648 standard, URL-safe, or JWT-style no-padding), or decode Base64 back to JSON. UTF-8 safe via TextEncoder, so emoji and non-ASCII strings round-trip cleanly.
How to Use Convert JSON to Base64
- Pick a mode - Encode (JSON โ Base64) or Decode (Base64 โ JSON). Switching modes auto-re-runs if you have input loaded.
- Format the JSON - minified for the smallest output, pretty-printed (2/4/tab indent) when humans need to read it, sort-keys for byte-stable deterministic encoding regardless of input key order.
- Pick a Base64 variant (encode) - Standard (RFC 4648 ยง4) is the default. URL-safe replaces
+ /with- _for URLs and filenames. URL-safe-no-padding strips trailing=- that's what JWTs use. - Paste and convert - Type or paste; the 200 ms debounce updates the output as you go. Ctrl+Enter (โ+Enter on Mac) forces a recompute. Invalid JSON shows the SyntaxError position.
- Read the stats line - input characters, UTF-8 byte count, Base64 character count, overhead percentage. Base64 inflation is typically ~33% (4 chars per 3 bytes).
- Decode handles all variants - paste any Base64 (standard, URL-safe, padded or not); we normalize back to standard form before decoding. If the decoded text isn't JSON, it's still returned as raw UTF-8 with a "non-JSON payload" tag.
- Copy or download - Copy uses the async Clipboard API with execCommand fallback. Download saves as
.b64.txt(encode) or.json(decode).
Frequently Asked Questions
Why is the encoder UTF-8 safe?
Many JSON-to-Base64 tools use btoa(unescape(encodeURIComponent(s))), which works but uses deprecated unescape. We use TextEncoder to get the UTF-8 byte sequence directly, then base64-encode those bytes. Emoji like ๐ in JSON string values round-trip cleanly – they’re 4-byte UTF-8 sequences, accurately preserved.
What’s the difference between the three Base64 variants?
Standard (RFC 4648 ยง4): A-Z a-z 0-9 + / with = padding. URL-safe (ยง5): replaces + with - and / with _ so the result can drop into URLs and filenames unescaped. URL-safe no-pad: also strips trailing =. That third one is what JWTs (RFC 7515) use – the header, payload, and signature are all URL-safe base64 with no padding.
Why does Base64 make my JSON bigger?
Because Base64 represents every 3 bytes of input as 4 ASCII characters – 4/3 โ 33% overhead. It’s not a compression scheme; it’s a transport scheme that fits arbitrary binary into a 7-bit-ASCII-safe character set. If you need actual compression, use gzip or brotli before encoding.
What’s “sort object keys” for?
JSON object key order isn’t guaranteed by the spec, so two systems can produce different-byte outputs for “the same” JSON. If you need a deterministic / canonical encoding (for hashing, signing, deduplication), turn on sort-keys. We recursively sort every object’s keys at every nesting depth before stringification.
Can I decode JWT payloads with this?
Yes. JWTs are three URL-safe-no-padding base64 segments separated by dots. Paste just the middle segment (the payload) into Decode mode – we’ll add padding back and decode the JSON inside. The header is also a URL-safe base64 JSON object; same trick works for it. We don’t verify signatures, so this is for inspection only.
What happens with invalid JSON?
The encoder runs JSON.parse first; if it throws, we surface the error message (most browsers include the position of the syntax error). The output stays empty and a red error toast appears.
What if the decoded Base64 isn’t JSON?
We still return the raw UTF-8 string and tag the result as “non-JSON payload”. Useful for inspecting URL-safe base64 from various APIs that don’t necessarily carry JSON. If the bytes aren’t even valid UTF-8 (e.g., it was actually a binary image), the decoder throws an error.
Is the round-trip lossless?
Yes – encode then decode returns the same JSON value (semantically). If sort-keys is on, the post-decode key order will be alphabetical, which may differ from the original order but represents the same object. String values, numbers, and nested structures are byte-identical.
Is my data uploaded anywhere?
No. All encoding/decoding happens via the browser’s built-in btoa/atob and TextEncoder/TextDecoder. Open DevTools โ Network and watch zero requests fire after the page loads. Safe for tokens, secrets, or any confidential JSON.
Does it work offline?
Yes. Total bundle is under 20 KB. Once the page loads, disconnect from the network and keep converting. Useful for working with JWTs or API payloads in air-gapped contexts.