You publish {"orderId":"A-1042","status":"paid"} to a Google Cloud Pub/Sub topic, point a push subscription at your webhook, and the first request that arrives has no orderId anywhere in it. What you get is an envelope, and your payload sits inside it as a string of letters that ends in ==.
That is how push delivery is meant to work. This post covers what the envelope contains, how to decode it correctly, and two bugs that are easy to recognise once you know what they look like: a publisher that Base64-encodes twice, and a handler that keeps decoding after someone switches the subscription to unwrapped delivery.
Sources: Google Cloud docs "Push subscriptions", "Payload unwrapping" and the REST reference for PubsubMessage, all read on 6 Dec 2026. The order event below is an illustrative example, not a real system.
What the push request actually looks like
By default Pub/Sub sends push messages wrapped: an HTTPS POST with a JSON body. The docs say plainly that "the message data is in the message.data field and is base64-encoded." Here is the structure with our illustrative order event inside it (IDs and times copied from the docs example; its duplicate snake_case fields message_id and publish_time are trimmed here):
{ "message": { "attributes": { "Content-Type": "application/json" }, "data": "eyJvcmRlcklkIjoiQS0xMDQyIiwic3RhdHVzIjoicGFpZCIsInRvdGFsIjoiNDkuOTAifQ==", "messageId": "2070443601311540", "publishTime": "2021-02-26T19:13:55.749Z" }, "subscription": "projects/myproject/subscriptions/mysubscription" } Three details are worth knowing:
- Only
datais Base64.attributesare plain string-to-string pairs, so do not decode them. -
datacan be missing. The REST reference says a message must have "either a non-empty data field or at least one attribute", so an attributes-only message is valid and your handler should not crash on it. - If the subscription uses authentication, the
Authorizationheader carries a JWT that Google signs. That is a separate thing fromdata. Verify it, but don't confuse it with your payload.
Worked example: decode it once
Input (illustrative): the data value above, 72 characters long.
Calculation: Base64 turns every 3 bytes into 4 characters, so 72 characters with == padding is 72 / 4 × 3 − 2 = 52 bytes. Our JSON {"orderId":"A-1042","status":"paid","total":"49.90"} is exactly 52 bytes of UTF-8.
Result: decoding gives back the original JSON, and then you parse it:
// Node.js const body = JSON.parse(rawRequestBody); const b64 = body.message && body.message.data; if (b64) { const order = JSON.parse(Buffer.from(b64, "base64").toString("utf8")); console.log(order.status); // "paid" } # Python import base64, json msg = body.get("message", {}) if "data" in msg: order = json.loads(base64.b64decode(msg["data"], validate=True)) We checked this in Node and Python, and also ran it through the JavaScript worker that base64decodetool.com uses. Decoding the 72 characters gave the 52-byte JSON with no warnings. As a sanity check, the docs' own unwrapping example eyJzdGF0dXMiOiAiSGVsbG8gdGhlcmUifQ== decodes to {"status": "Hello there"}, which is 25 bytes. That matches the Content-Length: 25 the docs show for the unwrapped version of the same message.
Bug 1: the publisher encoded it twice
This one turns up all the time. If you publish through the REST topics.publish endpoint, you Base64-encode data yourself, because the reference defines it as "a base64-encoded string". Client libraries usually take raw bytes and handle the wire format for you (the docs warn that they "represent this object differently depending on the language"). Mix the two approaches, for example by Base64-encoding a payload in your code and then passing it to a client library, and the subscriber receives Base64 of Base64.
You can spot it from the first characters:
What the push data starts with | What it usually means |
|---|---|
eyJ | Base64 of a JSON object whose first key starts with a letter ({" + letter). Decode once and you're done. |
ZXlK | Base64 of the text eyJ. It was encoded twice. |
Worked example (illustrative): encoding our 72-character Base64 string a second time gives a 96-character value that begins ZXlKdmNtUmxja2xr…. Decode it once and you don't get JSON. You get eyJvcmRlcklkIjoi…Q==, which is the first encoding, 72 bytes long. That's why JSON.parse fails. In Node 24 the error reads Unexpected token 'e', "eyJvcmRlck"... is not valid JSON. Character counts tell the same story: 52 bytes → 72 characters → 96 characters, because each pass multiplies the length by about 4/3.
Fix it at the publisher. Encode exactly once, in the place the API you're calling expects it. Don't paper over it by decoding twice in the subscriber, because the next publisher that does things correctly will then break your handler.
Bug 2: someone switched the subscription to unwrapped delivery
Push subscriptions can also use payload unwrapping. In that mode, per the docs, "the message data is delivered directly as the HTTP body", raw and already decoded. Metadata can optionally be sent as x-goog-pubsub-* headers if "write metadata" is enabled.
If your handler still runs a Base64 decode on that body, what happens depends on your language:
- Node.js:
Buffer.from('{"orderId":"A-1042",…}', "base64")doesn't throw. It skips the characters it doesn't like and returns 24 bytes of binary noise. - Python:
base64.b64decode(...)raisedbinascii.Error: Incorrect paddingon our example. Withvalidate=Trueit raisesOnly base64 data is allowed, which is the clearer failure.
So when a handler that used to work starts logging garbage after an infrastructure change, look at the subscription's push config first. It may now be delivering unwrapped.
Debugging it in the browser
When you just want to see what's inside a captured data value, without writing a script, you can paste it into the Base64 Decoder. It runs entirely in the browser:
- Leave the mode on Decode Base64 and the Character Set on UTF-8.
- Paste only the value of
message.data, not the whole JSON body. The decoder drops characters that aren't Base64, so a full envelope would be decoded as noise. - Read the output. If it starts with
eyJ, the payload was encoded twice; paste the output back in and decode once more to confirm. If you see "Notice: Output contains replacement characters", the bytes aren't UTF-8 text, so switch the Character Set to Hexadecimal to look at them.
Keep real customer data out of shared tools and screenshots anyway. Use a test message when you can.
Checklist
- Wrapped push: parse JSON → read
message.data→ Base64-decode once → parse your payload. - Handle a missing
datafield. Leaveattributesalone; they aren't encoded. -
ZXlKat the start ofdatameans it was encoded twice. Fix the publisher. - Unwrapped push: the body is already raw. Decoding it again gives garbage in Node and an exception in Python.
- Use strict decoding (
validate=Truein Python) so mistakes fail loudly.
Disclosure: this tool is from Mind vs Drive, the team behind this account.
The Mind vs Drive team
