JSON Input

Base64 Output

What Is JSON to Base64 Encoding?

Base64 is a binary-to-text encoding scheme defined in RFC 4648 that converts arbitrary bytes into 64 safe ASCII characters. Encoding JSON as Base64 is a common technique for embedding structured data in contexts where raw JSON might be unsafe or inconvenient — such as HTTP headers, JWT payloads, URL parameters, data URIs, and environment variables.

This tool parses your JSON, minifies it, encodes the text as UTF-8 bytes, and Base64-encodes those bytes with btoa(). The UTF-8 step matters: btoa() on its own only accepts Latin-1 and throws on emoji. Big integers (an ID like 8901240544102066246) keep every digit, which plain JSON.parse() wouldn't do. The reverse operation is handled by the Base64 to JSON tool.

How to Encode JSON to Base64

Follow these steps to Base64-encode your JSON data.

1

Paste or enter valid JSON

Paste your JSON into the input panel, or click Sample to load a JWT-style claims object for customer Ava Chen. The JSON must be valid; a syntax error is shown instead of output.

2

Instant Base64 output

The output updates as you type. The JSON is minified (whitespace removed), encoded as UTF-8, then Base64-encoded with btoa().

3

Copy the Base64 string

Click Copy to copy the Base64-encoded string to your clipboard. Paste it into your HTTP header, JWT, environment variable, or data URI.

Common Use Cases

JWT Payload Construction

JSON Web Tokens are three Base64URL-encoded parts: header, payload and signature. This tool gives you standard Base64, so for a JWT segment swap + for -, / for _ and drop the trailing =. Handy for building test tokens by hand; the signature still has to come from your signing library.

HTTP Header Embedding

HTTP headers cannot contain certain characters (newlines, binary data). Base64-encoding a JSON object produces a header-safe string that can be decoded on the server side.

Environment Variable Storage

A JSON config blob can go into a single Base64 environment variable, so you don't fight with quotes and newlines in Kubernetes Secrets, Docker Compose files or CI/CD pipeline settings. Note that Base64 is an encoding, not encryption: anyone who can read the variable can decode it.

Data URI Embedding

JSON data can be embedded directly in a web page or HTML email as a Base64 data URI, removing the need for a separate file or API request.

Frequently Asked Questions

Does the output need padding (=)?

The browser's btoa() function always produces standard Base64 with = padding. If you need Base64URL (used in JWTs and URLs), replace + with -, / with _, and strip the trailing = characters.

Does it handle emoji and non-English text?

Yes. btoa() on its own only accepts Latin-1 characters (code points 0 to 255), so it throws on emoji and CJK text and silently mis-encodes accented letters. This tool encodes your JSON as UTF-8 with TextEncoder first and Base64-encodes those bytes, which is what every other language's Base64 decoder expects.

Is my JSON validated before encoding?

Yes. The tool runs JSON.parse() on your input first. If the JSON is invalid, an error is shown and encoding is not performed.

Does my data leave my browser?

No. All encoding happens entirely in your browser. No data is transmitted to any server.

How do I decode Base64 back to JSON?

Use the Base64 to JSON tool. It accepts both standard Base64 and Base64URL, decodes the bytes as UTF-8 and pretty-prints the JSON.

Related Tools

Explore more encoding, decoding, and JSON utilities on jsonparser.ai.