Encode a JSON document as UTF-8 Base64 text
JSON to Base64 encodes the UTF-8 bytes of a valid JSON document into a standard Base64 string. Some APIs use this representation for a data field or transport envelope.
When should you use it?
- Fill a Base64 JSON field required by an integration.
- Compare encoded output for a known payload.
- Move a JSON document through a text-only channel.
Example: encode JSON text
This is a reversible transport encoding of UTF-8 bytes, not a way to conceal data.
{"a":1}eyJhIjoxfQ==Know what the Base64 layer contains
The tool first checks strict JSON, then encodes the original UTF-8 text. Its whitespace and non-ASCII characters are therefore part of the encoded bytes. Two equivalent JSON documents with different indentation can produce different Base64 strings. Minify first only when you deliberately want to encode the compact representation.
Use the alphabet required by the receiving field
This output is standard Base64, with padding where required. A URL-safe Base64 field or a JWT segment uses different conventions and should not be treated as interchangeable. Base64 also expands the byte representation rather than compressing it. It is an encoding for transporting bytes as text and provides no secrecy; anyone with the encoded text can decode the JSON.
How do I encode a JSON document as standard Base64 for an API field?
Validate the JSON text, then encode its UTF-8 bytes. The output uses the standard Base64 alphabet and padding, which differs from the base64url segments commonly found in JWTs. Because the exact text is encoded, changing indentation changes the Base64 result.
JavaScript: a comparable UTF-8 Base64 operation
javascriptconst json = '{"a":1}';
const bytes = new TextEncoder().encode(json);
const base64 = btoa(String.fromCharCode(...bytes));
// eyJhIjoxfQ==This short browser example illustrates the encoding. The site handles bounded input in chunks and validates JSON before encoding.
Does Base64 protect private JSON?
No. Anyone with the encoded text can reverse it. Use a real security mechanism when confidentiality or integrity matters.
What should you check before using the result?
Base64 is reversible and offers no secrecy or integrity check. Do not use it as encryption; decode and validate again at the receiving end.
Understand JSON syntaxTechnical reference: Base64 alphabets and padding · RFC 4648