Why use this encoder
UTF-8 aware
Uses TextEncoder and TextDecoder for proper Unicode handling. Emoji, CJK characters, and accented letters all encode and decode correctly.
URL-safe variant
Standard Base64 uses + and / which break URLs. The URL-safe variant replaces them with - and _, and strips padding.
Optional minification
When encoding, optionally minify the JSON first for the smallest possible Base64 output. Useful for tokens and compact storage.
Conversion explained
1. Take input
For encoding, the input is treated as a JSON string (optionally parsed and re-serialized for minification). For decoding, the input is treated as a Base64 string.
2. Convert bytes
Encoding: UTF-8 encode the JSON, then Base64 encode the bytes. Decoding: Base64 decode to bytes, then UTF-8 decode to text.
3. Optional URL-safe
If URL-safe mode is on, +/- and /_ are swapped, and padding = is stripped (encode) or restored (decode).
JSON to Base64 Encoder / Decoder — frequently asked questions
Why use Base64 for JSON?
Base64 encodes binary data as ASCII text, making it safe to transmit over text-only channels (URLs, cookies, email, JSON strings inside other JSON). It's commonly used for JWT tokens, data URLs, and compact data embedding.
What's the URL-safe variant?
Standard Base64 uses + and /, which have special meanings in URLs and need percent-encoding. URL-safe Base64 replaces them with - and _, and strips padding =, producing a string that's safe in URLs without further encoding.
How much larger is Base64 than the original JSON?
About 33%. Base64 encodes every 3 bytes as 4 characters, so the output is approximately 4/3 the size of the input. For JSON, this typically means a 33% overhead compared to the original UTF-8 bytes.
Is Base64 encryption?
No. Base64 is encoding, not encryption. Anyone can decode it — it provides no confidentiality. For sensitive data, use proper encryption (e.g., AES-GCM) before Base64 encoding. Base64 is for transport, not security.