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 encodes your JSON using btoa(JSON.stringify(parsedJson)). It first validates and minifies your JSON via JSON.parse() and JSON.stringify(), then Base64-encodes the result. The reverse operation — decoding — is handled by our 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 an example. The JSON must be valid — syntax errors will be flagged before encoding.

2

Instant Base64 output

The tool validates the JSON, minifies it with JSON.stringify(), and then Base64-encodes it with btoa(). The result appears immediately in the output panel.

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 consist of three Base64URL-encoded parts — header, payload, and signature. Encode a JSON claims object here to construct or inspect JWT segments manually.

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

Complex JSON configuration blobs can be compressed into a single Base64 environment variable, simplifying secrets management in Kubernetes, Docker Compose, and CI/CD pipelines.

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.

Why does encoding fail for some JSON?

btoa() can only encode Latin-1 characters (code points 0–255). If your JSON contains characters outside this range — such as CJK characters, emoji, or other Unicode — you need to UTF-8 encode first. This tool uses unescape(encodeURIComponent(str)) internally to handle Unicode correctly.

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 our companion Base64 to JSON tool, which applies atob() + JSON.parse() with pretty-printing.

Related Tools

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