FormatterHQ

JSON to Base64

Validate a JSON document and encode it as Base64 or Base64URL in one step — ready for API fields, HTTP headers, config values and tokens.

Loading tool…
Ready.

How to use the JSON to Base64

  1. Type or paste into the JSON box, or click Sample. You can also drop a file on a box or use its Open file button.
  2. The Base64 box updates live as you type. It works both ways — edit the Base64 side to convert back, or click ⇄ Swap to exchange the sides.
  3. Adjust Alphabet and Wrap lines at 76 chars (MIME) in the options bar above the editors; the result refreshes immediately.
  4. Use Copy or Download on either box to take the result, or Clear to start again.

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/dockerconfigjson secrets, whose .dockerconfigjson value 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.

Frequently asked questions

Does the tool minify my JSON before encoding?
No. It encodes the JSON exactly as you entered it. Minify it first if you want the shortest Base64 string.
Why does Base64 JSON often start with eyJ?
Minified JSON objects begin with {" and those two bytes encode to eyJ in Base64. That is why JWT headers and payloads start with eyJ.
What happens if my JSON is invalid?
Encoding stops and the parser’s error message is shown, including the position of the problem, so you can fix it before sending the payload.
Is Base64-encoded JSON secure?
No. Base64 can be decoded by anyone. Encrypt the data or keep it server-side if it contains secrets.

Last updated October 3, 2026

Related tools