Base64 Encode JSON Online
Encode JSON data to Base64 format. Useful for API payloads, configuration storage, and data URIs.
Open Base64 Encoder →Why Base64 Encode JSON?
Base64-encoding JSON is common when you need to embed structured data in contexts that only support plain strings. Use cases include: JWT payloads (the payload section of a JWT is Base64url-encoded JSON), query parameters (encoding a JSON filter as a URL-safe string), environment variables (storing JSON config as a single env var), and HTTP headers (passing structured metadata in custom headers that only support ASCII).
How to Base64 Encode JSON in Code
In JavaScript:
btoa(JSON.stringify(obj)) encodes an object. To decode: JSON.parse(atob(encoded)). For UTF-8 safety, use btoa(unescape(encodeURIComponent(JSON.stringify(obj)))). In Python: base64.b64encode(json.dumps(obj).encode()).decode(). Always ensure your JSON is valid before encoding — invalid JSON encoded in Base64 will still be invalid when decoded.// JavaScript
const obj = { name: "John", role: "admin" };
const encoded = btoa(JSON.stringify(obj));
// "eyJuYW1lIjoiSm9obiIsInJvbGUiOiJhZG1pbiJ9"
const decoded = JSON.parse(atob(encoded));
// { name: "John", role: "admin" }
// Python
import base64, json
encoded = base64.b64encode(json.dumps(obj).encode()).decode()