Developers
Decode a Base64 Webhook Payload and Generate Its Schema and Types
ยท 6 min read
To make sense of a webhook or queue message whose body arrives as Base64, decode the data field back to text first, then unescape any JSON that was stored as a string inside it. Open the result as a tree to find the paths you need, and generate a JSON Schema and TypeScript interfaces from that one sample so your handler can check and type the data. Emojar has a free tool for each step: the Base64 Decoder, String Escape / Unescape, the JSON Viewer & Tree Explorer, the JSON Schema Generator and JSON to TypeScript. They run in your browser and nothing you paste is uploaded, so a payload with a real customer email in it stays on your machine.
The example follows Tom, who is wiring up an "order paid" event for a small online shop. The shop's message queue pushes each event to his endpoint as an envelope like this:
{
"message": {
"data": "eyJldmVudCI6Im9yZGVyLnBhaWQiLCJvcmRlcklkIjoiQS0xMDQyIiwiYW1vdW50Ijo0OS41LC...",
"messageId": "9184",
"publishTime": "2026-11-28T09:14:05Z"
},
"subscription": "orders-push"
}
The order is inside that data string, so Tom can't read his logs until he decodes it.
How do I decode the Base64 data field?
Tom copies the whole value of message.data from his log and pastes it into the Base64 Decoder. The decoder works as you type, so the Decoded text box fills in at once and there's no button to press. For Tom's message it shows a single line of JSON:
{"event":"order.paid","orderId":"A-1042","amount":49.5,"currency":"EUR","paidAt":"2026-11-28T09:14:02Z","customer":{"email":"lena@example.com","note":null},"items":[{"sku":"MUG-01","qty":2},{"sku":"TEE-M","qty":1,"giftWrap":true}],"meta":"{\"source\":\"checkout\",\"retry\":0}"}
The decoder accepts standard Base64 and the URL-safe Base64URL variant, with or without the = padding at the end, and it ignores whitespace, so a value that wrapped across lines in a log still decodes. If the bytes inside aren't valid UTF-8 text, it says so and points you to Base64 to Image, because that usually means the field holds a picture or another binary file.
Why is there JSON inside a string, and how do I read it?
The last field, meta, is a string that holds JSON, with every quote escaped as \". You get this when the sending service serialises a value twice, and it's common with metadata fields that the sender treats as opaque.
Tom copies the value of meta, quotes included, into String Escape / Unescape. He sets Mode to Unescape and leaves Format on "JSON string", the default. The Result box shows:
{"source":"checkout","retry":0}
The surrounding double quotes can stay in the input, because the JSON unescape strips one pair from the start and end before decoding. If it complains, the usual cause is a stray " or \ in the middle that wasn't escaped, or a \u not followed by four hex digits.
Now Tom knows the retry counter lives in that string. His handler will need to call JSON.parse on meta a second time to reach it, and a schema generated from the outer document will only ever describe meta as a string.
How do I find the path to a value in a JSON payload?
This order is small, but real events often run to dozens of nested keys. Tom pastes the decoded JSON into the JSON Viewer & Tree Explorer. The tree shows every object with its number of keys and every array with its number of items, and each value is labelled string, number, boolean or null. items shows 2 items. customer.note is labelled null.
He wants the gift-wrap flag, so he types giftWrap into Search. The viewer highlights the match and opens its parents. He clicks the value and presses Copy JSON path, which gives:
items[1].giftWrap
With Start paths with $ (JSONPath) ticked, the same node copies as $.items[1].giftWrap, which is the form JSONPath libraries and Postman-style tests expect. Copy value copies just true, and Copy subtree copies the selected node as formatted JSON, which is handy for pulling one line item out as a test fixture. If the payload won't parse, the viewer reports the line and column of the first error. Trailing commas and single quotes are the usual suspects.
How do I generate a JSON Schema from a sample payload?
Tom wants his endpoint to reject malformed events before they reach the database. He pastes the decoded order into the JSON Schema Generator and keeps the defaults: JSON Schema version on "Draft 2020-12 (default)", Mark keys found in every object as required ticked, and Detect formats (date-time, email, uri, uuid) ticked.
Tom checks a few lines of the result:
paidAtcomes out as"type": "string", "format": "date-time", andcustomer.emailas"format": "email".amountis"type": "number"because 49.5 has a decimal part, whileqtyis"type": "integer".- The two line items are merged into one
itemsschema.skuandqtyappear in both, so they're listed underrequired.giftWrapappears only in the second item, so it's a property but not required. customer.noteis"type": "null", because null is the only value the sample shows.
Tom fixes that one by hand. He knows a note can be a string, so he edits it to "type": ["string", "null"]. He also ticks No extra keys (additionalProperties: false) for the line items, so a typo such as qnty gets rejected. That option adds the rule to every object in the schema, so he removes it again from the top level, where the shop may add fields later. If his validator only supports older drafts, he can pick Draft-07 instead; for schemas this tool produces, only the $schema URI changes.
The download saves the result as schema.json.
How do I turn the payload into TypeScript interfaces?
Last, Tom wants types for the handler code. He pastes the same decoded JSON into JSON to TypeScript, sets Root type name to OrderPaid and leaves Declare as on interface. The output updates as he types:
export interface OrderPaid {
event: string;
orderId: string;
amount: number;
currency: string;
paidAt: string;
customer: Customer;
items: Item[];
meta: string;
}
export interface Item {
sku: string;
qty: number;
giftWrap?: boolean;
}
export interface Customer {
email: string;
note: null;
}
The array called items produced an interface called Item, and giftWrap became optional (?) because one of the two items didn't have it. The same null problem shows up here: note is typed as null, so Tom changes it to string | null. He also adds a small Meta interface with source: string and retry: number for the parsed contents of meta, by pasting {"source":"checkout","retry":0} into the tool with the root name Meta.
If his team prefers type aliases, Declare as has a "type alias" option, and readonly properties marks every field as readonly.
FAQ
Why does the Base64 Decoder say the data is not valid UTF-8 text?
The bytes inside the Base64 aren't text. The field probably holds an image, a compressed file or another binary format. If it's an image, paste it into Base64 to Image instead.
Can I unescape a string that still has its quotes around it?
Yes. With Format set to "JSON string", String Escape / Unescape removes one double quote from the start and the end of the input before decoding, so you can paste the value exactly as it appears in the JSON.
Will the generated schema catch every bad payload?
No. It describes the sample you pasted: types, nesting and which keys every object had. It can't know maximum lengths, allowed values, number ranges or optional fields that happened to be missing, so review it and add those rules yourself.
Is the payload sent anywhere when I paste it?
No. Decoding, unescaping, parsing and the schema and type generation all happen in your browser, so you can paste an event that contains real customer data.
More JSON, encoding and API helpers are in Developer Tools.
