A courier's JSON response contains the shipping label as a long Base64 string. How do I turn it back into a file I can open?

Paste the Base64 value on its own, without the surrounding quotes, in 'Decode' mode. When the bytes are not text, the tool shows the file type it recognised and the first bytes, and lets you download the file with a suitable extension. A value starting with something like data:application/pdf;base64, is accepted too.

Published · 3 min read

Why the label arrives as text

A JSON response is text, and it cannot carry the raw bytes of a PDF or an image. So couriers and many other systems write the file in Base64: letters, digits and a couple of symbols that pass through text without trouble. The file has not changed; it is just written another way, and decoding gives back the original bytes exactly.

Remember that Base64 is encoding, not encryption: anyone who gets hold of this text can turn it back into the label and read the customer's address and phone number. Treat it as you would the file itself.

How the tool tells the file type

Every file format starts with fixed bytes called a signature. We tried the tool on the start of a PNG file:

iVBORw0KGgo=

It reported that the result is not UTF-8 text, that the file type from its signature is PNG, and that the first bytes are 89 50 4E 47 0D 0A 1A 0A, followed by a 'Download the data as a file' button that saves it as decoded.png. The types it recognises are PNG, JPEG, GIF, WebP, PDF, ZIP and GZIP; anything else downloads with a .bin extension, which you can rename yourself if you know the type.

Steps

  1. In the JSON response, copy only the long value, from the first character after the opening quote to the last one before the closing quote.
  2. Open the Base64 encoder/decoder tool, choose 'Decode' and paste the value.
  3. Read the note: the file type and the size of the data.
  4. Press 'Download the data as a file' and open the result.

Common copying mistakes from JSON

  • Copying the quote along with the value: we tried it and the tool refused with 'Position 1: a character that is not in the Base64 alphabet', pointing at the quote.
  • Escaped slashes: some JSON writers put / as \/ inside strings. A backslash is not in the Base64 alphabet, so the tool refuses it and gives its position. Delete the backslashes, or copy the value from a JSON viewer that shows it unescaped.
  • A cut-off value: if the response is long and the program you view it in trims it, the tool may refuse the length or give you an incomplete file that will not open. Copy the value from the full response.

What if the output shows as text starting with %PDF?

The tool shows the result as text when all of its bytes are valid characters. We tried a very short start of a PDF and it appeared as text beginning %PDF-1.4. That means the bytes are a PDF, but this part happens to hold only characters. In that case download the output with the text button and change the file's extension to .pdf; the bytes are preserved.

If the label is an image in a format your printer or software dislikes, you can convert it after downloading with the Image format converter.

Common questions

Is the label uploaded to a server while decoding?

No. Decoding runs inside your browser, and neither the text nor the file is sent anywhere.

Is there a length limit?

Yes, two million characters of pasted text, which covers a file of about 1.5 MB.

Does the tool open the file itself?

No. It restores the bytes and lets you download them. Open the file in the right program on your device.