How to encode an excel file to base64 for embedding in json api payloads
- Step 1Upload the workbook — Drop the
.xlsx(or.xls/.ods/.csv) you want to embed. The picker is restricted to those extensions. - Step 2Encode locally —
file.arrayBuffer()reads the bytes; they're chunked into 32 KB segments and run throughbtoa()— all in the page, no network call. - Step 3Note the MIME and byte count — Line 1 gives the byte count; line 2 gives the MIME (or
application/octet-streamfallback). You'll often need both in the JSON object. - Step 4Copy the output — Copy grabs the whole block —
//comment lines included. Paste into an editor first. - Step 5Trim to the raw string — Remove the two
//lines and the blank separator. The remaining text is the value for your JSON file field. - Step 6Build the JSON object — Assemble
{ "filename": ..., "contentType": <MIME line>, "data": <raw base64> }to match your endpoint's schema, then send via curl/Postman/code.
What the output text contains
The JSON file field needs only the raw Base64 (Line 4+). Lines 1-3 are reference text the tool prints; strip them before embedding.
| Line | Example content | Keep it for API use? |
|---|---|---|
| Line 1 | // Base64-encoded: report.xlsx (48,213 bytes) | No — strip it |
| Line 2 | // MIME type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet | No — but copy the MIME value into your payload |
| Line 3 | (blank separator line) | No — strip it |
| Line 4+ | UEsDBBQABg... (the raw Base64, no data: prefix) | Yes — this is the only part the API needs |
Common JSON field names for inline files
APIs disagree on what to call the Base64 field. The byte count and MIME the tool prints map to the metadata fields below. Field names are illustrative — check your endpoint's docs.
| API style | Bytes field | MIME / type field | Filename field |
|---|---|---|---|
| Generic REST | file / data | contentType | filename |
| Document/OCR services | content / document | mimeType | name |
| Webhook relay | payload / attachment | type | filename |
| Microsoft Graph | contentBytes | contentType | name |
File-size limits by plan (excel family)
The Base64 string is ~33% bigger than the source, so check it against your API's request-body size cap as well as the JAD plan cap.
| Plan | Max source file | Approx. Base64 output (+33%) | Files per run |
|---|---|---|---|
| Free | 5 MB | ~6.7 MB | 1 |
| Pro | 50 MB | ~66.5 MB | 5 |
| Pro-media | 200 MB | ~266 MB | 20 |
| Developer | 500 MB | ~665 MB | unlimited |
Cookbook
Real request shapes built from the tool's literal output. In every case the JSON value is the raw Base64 only — the // lines are stripped first.
Single-object JSON body with metadata
The most portable shape: file bytes plus the metadata the tool already printed for you.
Tool output:
// Base64-encoded: invoices.xlsx (62,940 bytes)
// MIME type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
UEsDBBQABg...
POST /v1/process
{
"filename": "invoices.xlsx",
"contentType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"data": "UEsDBBQABg..."
}curl with the Base64 inlined
For a quick test from the terminal, paste the raw string into a JSON string literal.
curl -X POST https://api.example.com/v1/ingest \
-H 'Content-Type: application/json' \
-d '{"file":"UEsDBBQABg...","type":"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}'Validate before sending: decoded length must match
Catch a truncated paste early. The header's byte count is the ground truth.
// header: invoices.xlsx (62,940 bytes) node> Buffer.from(b64, 'base64').length 62940 // OK — full string pasted
Webhook payload wrapping the file
Some integration platforms wrap the file inside an event envelope. The Base64 still goes in one string field.
{
"event": "file.received",
"attachment": {
"name": "export.xlsx",
"mime": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"base64": "UEsDBBQABg..."
}
}When the API wants a data URI instead
A minority of APIs (and some <img>/<a> embeds) want a full data URI. Build it yourself from the printed MIME — the tool does not add the prefix.
// MIME type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,UEsDBBQABg... ^------ you prepend this part ------^
Edge cases and what actually happens
Whole text block pasted as the JSON value
Invalid JSONIf the // comment lines end up inside the JSON string, the value is corrupt — the bytes won't decode to a valid workbook. Strip the first three output lines first.
API rejects request as too large
413 payload too largeBase64 adds ~33%, and the JSON envelope adds more. A 50 MB workbook becomes ~66.5 MB of Base64 — over many gateways' body limits. Use a multipart/upload-session API for big files.
Sending raw Base64 to an API that wants a data URI
RejectedSome fields require the data:<mime>;base64, prefix. The tool emits raw Base64 only, so prepend the prefix yourself using the printed MIME line.
Wrong MIME in the metadata field
Processing errorIf the browser printed application/octet-stream and you forward that, a strict API may refuse to parse the spreadsheet. Substitute the correct Office MIME manually.
Truncated paste from a giant string
Decode failureCopying a multi-MB string from the preview can drop characters in some editors. Use Download instead, and verify decoded length against the header byte count.
.csv embedded as bytes
SupportedA CSV is encoded verbatim (MIME text/csv). If the endpoint actually wants JSON rows rather than a Base64 blob, encode is the wrong step — parse the CSV instead.
Free tier on a 6 MB export
RejectedFree caps at 5 MB source. Trim sheets, split the workbook, or upgrade to Pro (50 MB) before encoding.
Non-spreadsheet file needed in the same payload
Not selectableThe picker only accepts spreadsheet extensions. Encode other file types with a general file-to-Base64 tool, then assemble the combined JSON.
Need typed code from the sheet, not a blob
Use sibling toolIf the API wants structured data rather than the raw file, generate it with the Python Dict/List Generator or tRPC Router Builder instead of Base64.
Frequently asked questions
Do I include the data URI prefix in my JSON?
Usually no — most JSON file fields want the raw Base64 only, which is exactly what this tool emits. Add a data:<mime>;base64, prefix yourself only if the API documents that it needs one.
Which part of the output goes in the JSON value?
Only the raw Base64 below the blank line. Strip the two // comment lines and the blank separator first.
What MIME type should I send for .xlsx?
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet — and the tool already prints it on line 2, so you can copy it directly.
How do I check the string isn't truncated?
Decode it (Buffer.from(b64,'base64').length or atob(b64).length) and confirm the length equals the byte count in the output header.
Is there a request-size concern?
Yes — Base64 is ~33% larger than the source and JSON adds overhead, so large workbooks can exceed gateway body limits. Prefer an upload session for big files.
Does the file get uploaded to encode it?
No. Encoding is fully browser-side via file.arrayBuffer() and btoa(). The workbook stays on your machine.
Can I encode CSV for a JSON API?
Yes, the bytes are encoded as-is with MIME text/csv. But if the API wants rows, parse the CSV rather than Base64-encoding it.
What file types does the picker accept?
.xlsx, .xls, .ods, .csv. Other extensions aren't selectable in this tool.
What's the max file size?
Free 5 MB, Pro 50 MB, Pro-media 200 MB, Developer 500 MB — measured on the source file.
Will the Base64 match what my backend computes?
Yes. It's standard, deterministic Base64, so client and server produce the same string from the same bytes.
Can I decode the Base64 back to a workbook here?
Not yet. Use a decoder or atob() for now; decoding is planned.
What related tools help with API integration?
See the tRPC Router Builder, the Python Dict/List Generator, and the i18n JSON Generator.
Privacy first
Every JAD Excel tool runs entirely in your browser using SheetJS and ExcelJS. Your spreadsheets, formulas, and data never leave your device — verified by zero outbound network requests during processing.