JSON to Base64 with validation
Many systems carry JSON inside another format as a Base64 string: API fields that accept an “encoded payload”, HTTP headers, cookies, message attributes, and configuration values that must be a single line. The JSON to Base64 tool first checks that your input is valid JSON — so you never ship a broken payload — and then encodes it as UTF-8 Base64.
Example
Input:
{
"id": 42,
"name": "Widget",
"tags": ["new", "sale"]
}Output:
ewogICJpZCI6IDQyLAogICJuYW1lIjogIldpZGdldCIsCiAgInRhZ3MiOiBbIm5ldyIsICJzYWxlIl0KfQ==The result starts with ewog because the JSON begins with a brace and a line break. Minified JSON starting with {" always encodes to eyJ — the familiar prefix of every JWT header and payload.
Validation first
If the JSON is invalid, you get the parser’s error message with the line and column, for example Expected double-quoted property name for a trailing comma. Fix it here, or run the document through the JSON Validator for a more detailed report. Once valid, the text is encoded exactly as typed: whitespace and key order are preserved.
Standard or URL-safe?
- Standard Base64 (
+ / =) is right for JSON bodies, YAML or XML fields and most APIs. - URL-safe Base64 (
- _, no padding) is required for JWT-style tokens, query parameters, cookie values and file names.
Where Base64-encoded JSON is used
- Kubernetes
kubernetes.io/dockerconfigjsonsecrets, whose.dockerconfigjsonvalue is Base64-encoded JSON. - JSON Web Tokens, whose header and payload are Base64URL-encoded JSON objects.
- Webhook and message queue attributes that only accept strings.
- Browser storage or URL state where a compact, opaque string is preferred.
Encoding JSON in code
In the browser, btoa(JSON.stringify(obj)) throws as soon as a string contains a character above U+00FF, such as “€” or an emoji; encode to UTF-8 first, or use Buffer.from(JSON.stringify(obj)).toString('base64') in Node.js. In Python, use base64.b64encode(json.dumps(obj).encode()). Note that different serializers produce different whitespace and key order, and each variation gives a different Base64 string — important if the value is signed or compared.
Size tips
Base64 adds a third to the size, and indentation is encoded too. Minify the JSON first with JSON Minify when size matters. Remember that encoding is not encryption: anyone can decode the value with Base64 to JSON, so do not treat Base64 as a way to hide credentials.
The encoding runs locally in your browser.