MergeJSON

How to Convert JSON to Base64

Learn how to convert JSON to Base64, decode Base64 back to JSON, use URL-safe Base64, create JSON data URIs, wrap Base64 lines, and minify before encoding.

Published June 14, 2026

Base64 is a common way to move JSON through systems that expect text-safe encoded data. You might use it in test fixtures, API examples, config values, data URIs, message payloads, or places where raw braces and quotes are awkward.

To convert JSON to Base64, you first validate the JSON, choose whether to minify or preserve formatting, then encode the JSON text as Base64. This guide covers standard Base64, URL-safe Base64, data URI output, line wrapping, and decoding Base64 back to JSON.

The quickest way: JSON to Base64 online

Paste JSON into the JSON to Base64 tool, choose standard or URL-safe Base64, and press Encode JSON to Base64. The tool validates your JSON first, optionally minifies it, then gives you a Base64 string you can copy or download.

Everything runs in your browser, so private JSON is not uploaded.

Use it when: you need to encode JSON for an API field, data URI, config value, test fixture, token payload, or encoded documentation example.

Example: encode JSON to Base64

JSON input:

{
  "name": "merge-json",
  "version": 2,
  "private": true
}

Minified before encoding:

{"name":"merge-json","version":2,"private":true}

Base64 output:

eyJuYW1lIjoibWVyZ2UtanNvbiIsInZlcnNpb24iOjIsInByaXZhdGUiOnRydWV9

Minifying first usually makes the Base64 output shorter because Base64 encodes every byte of whitespace too.

Decode Base64 to JSON

A good JSON Base64 converter should also reverse the process. In the online tool, switch to Base64 to JSON mode, paste Base64, and decode it. The result is parsed as JSON so you know the decoded content is valid.

Decode mode accepts:

  • Standard Base64
  • URL-safe Base64
  • Wrapped Base64 with line breaks
  • JSON data URIs such as data:application/json;base64,...

Standard Base64 vs URL-safe Base64

Standard Base64 can include +, /, and = padding. That is fine in many files and payloads, but those characters can be inconvenient in URLs.

URL-safe Base64 changes the alphabet:

  • + becomes -
  • / becomes _
  • Padding = is usually removed

Use URL-safe Base64 JSON for query strings, URL paths, routing parameters, or systems that reject standard Base64 symbols.

JSON data URI output

A JSON data URI looks like this:

data:application/json;base64,eyJuYW1lIjoibWVyZ2UtanNvbiJ9

This is useful when a system expects a single URI-like value instead of raw JSON or raw Base64. The tool can generate application/json data URIs by default, or text/plain when that is the safer MIME type for your destination.

Wrap or chunk Base64 lines

Some older systems, email formats, and command-line workflows expect Base64 to be wrapped at a fixed line length. Common widths are 64 or 76 characters.

Raw Base64 can be wrapped without changing the decoded value because decoders usually ignore whitespace. Data URIs should stay unwrapped so the URI remains copy-ready.

Convert JSON to Base64 in JavaScript

For ASCII-only JSON, a tiny browser example looks like this:

const json = JSON.stringify({ name: "merge-json", version: 2 });
const base64 = btoa(json);

For real JSON, use UTF-8 so non-English text and emoji are encoded correctly:

function jsonToBase64(value) {
  const json = JSON.stringify(value);
  const bytes = new TextEncoder().encode(json);
  let binary = "";
  bytes.forEach((byte) => {
    binary += String.fromCharCode(byte);
  });
  return btoa(binary);
}

Production tools add validation, URL-safe output, data URI output, line wrapping, Unicode-safe decoding, and Base64 to JSON mode.

Is Base64 encryption?

No. Base64 is encoding, not encryption. Anyone can decode it back to the original JSON. Do not use Base64 to hide secrets. Use it only when you need a transport-safe text representation.

For one-off conversion, use the JSON to Base64 online tool. Before encoding, you can also clean up the input with JSON Formatter, JSON Minifier, or JSON Validator.

Ready to merge your JSON?

Combine files or snippets in your browser — free and private.

Open the merge tool

Keep reading