Base64 to JSON API Documentation¶
Overview¶
This API converts a Base64-encoded JSON string into a human-readable, pretty-printed JSON format.
It supports three input modes:
- Body Mode (direct Base64 string in request body)
- URL Mode (remote file URL)
- File Mode (uploaded file reference)
The output is a formatted JSON file stored temporarily and accessible via a secure download link.
Endpoint (POST)¶
POST https://api.apidatatools.com/base64-to-json-api
Headers¶
| Header | Description | Required | Example |
|---|---|---|---|
Content-Type | Must be application/json | Yes | application/json |
x-source-type | Defines input mode: body, url, or file | Optional (defaults to body) | x-source-type: body |
x-api-key | API key | Yes | <api key> |
Accepted File Extensions¶
Allowed extensions for this tool:
.txt, .log
Input Example (Body Mode)¶
eyJrZXkiOiAidmFsdWUifQ==
Input Example (URL Mode)¶
{
"url": "https://example.com/sample.txt"
}
x-source-type: url
Input Example (File Mode)¶
{
"file": "user_uploads/upl_12345/sample.txt"
}
x-source-type: file
Example Request¶
Synchronous (Body Input)¶
curl -X POST "https://api.apidatatools.com/base64-to-json-api" \
-H "Content-Type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
-d 'eyJrZXkiOiAidmFsdWUifQ=='
Asynchronous (Remote File URL)¶
curl -X POST "https://api.apidatatools.com/base64-to-json-api" \
-H "Content-Type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
-H "x-source-type: url" \
-d '{"url": "https://example.com/sample.txt"}'
Asynchronous (Input File)¶
curl -X POST "https://api.apidatatools.com/base64-to-json-api" \
-H "Content-Type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
-H "x-source-type: file" \
-d '{"file": "user_uploads/upl_12345/sample.txt"}'
Example Response¶
Successful (Body Mode)¶
{
"request_id": "b7f1c3e2-9a4b-4f8a-9e12-2c9a7b8c5e3f",
"status": "success",
"file": "https://downloads.apidatatools.com/apidatatools_convert_abc123.json",
"preview": "{\n \"key\": \"value\"\n}"
}
Async Job Accepted¶
{
"status": "accepted",
"job_id": "job_9f8a7b6c5d4e3f2a1b0c",
"status_url": "https://api.apidatatools.com/jobs/job_9f8a7b6c5d4e3f2a1b0c",
"request_id": "b7f1c3e2-9a4b-4f8a-9e12-2c9a7b8c5e3f"
}
Error Handling¶
| Error Code | Description | Example Response |
|---|---|---|
BASE64_DECODE_FAILED | Invalid Base64 input | {"status":"error","error":"BASE64_DECODE_FAILED","details":{"message":"Failed to decode Base64 input."}} |
UTF8_DECODE_FAILED | Decoded data not valid UTF-8 | {"status":"error","error":"UTF8_DECODE_FAILED","details":{"message":"Base64 decoded data is not valid UTF-8 text."}} |
INVALID_JSON | Decoded content is not valid JSON | {"status":"error","error":"INVALID_JSON","details":{"message":"Decoded Base64 content is not valid JSON."}} |
INVALID_BODY_ENCODING | Body could not be decoded | {"status":"error","error":"INVALID_BODY_ENCODING","details":{"message":"Failed to base64-decode request body."}} |
EMPTY_BODY | Request body missing | {"status":"error","error":"EMPTY_BODY","details":{"message":"Request body is empty."}} |
FILE_TOO_LARGE | File exceeds plan limit | {"status":"error","error":"FILE_TOO_LARGE","details":{"message":"File exceeds plan limit."}} |
INVALID_URL | Invalid or missing URL | {"status":"error","error":"INVALID_URL","details":{"message":"Missing or invalid 'url'."}} |
URL_UNREACHABLE | URL cannot be reached | {"status":"error","error":"URL_UNREACHABLE","details":{"message":"Could not reach URL."}} |
URL_NOT_OK | URL returned non-200 status | {"status":"error","error":"URL_NOT_OK","details":{"message":"URL returned HTTP 404, expected 200."}} |
INVALID_FILE | Invalid file reference | {"status":"error","error":"INVALID_FILE","details":{"message":"Missing or invalid 'file'."}} |
INVALID_FILE_EXTENSION | Unsupported file extension | {"status":"error","error":"INVALID_FILE_EXTENSION","details":{"message":"Invalid or unsupported file extension."}} |
PAYLOAD_TOO_LARGE | Body exceeds allowed size | {"status":"error","error":"PAYLOAD_TOO_LARGE","details":{"message":"Request body exceeds limit."}} |
INTERNAL_ERROR | Unexpected server error | {"status":"error","error":"INTERNAL_ERROR","details":{"message":"Failed to process your request"}} |
Async Job Status¶
To check the status of an asynchronous job (URL or File mode):
Endpoint¶
GET https://api.apidatatools.com/jobs/{job_id}
Example Status Response for Async¶
Queued¶
{
"job_id": "job_9f8a7b6c5d4e3f2a1b0c",
"status": "queued",
"message": "Your job is being processed.",
"retry_after": 2
}
Success¶
{
"job_id": "job_9f8a7b6c5d4e3f2a1b0c",
"status": "success",
"created_at": 1712345678,
"updated_at": 1712345689,
"result": {
"request_id": "b7f1c3e2-9a4b-4f8a-9e12-2c9a7b8c5e3f",
"status": "success",
"file": "https://downloads.apidatatools.com/apidatatools_convert_abc123.json",
"preview": "{\n \"key\": \"value\"\n}"
}
}
Failed¶
{
"job_id": "job_9f8a7b6c5d4e3f2a1b0c",
"status": "failed",
"error": {
"code": "INVALID_JSON",
"message": "Decoded Base64 content is not valid JSON.",
"details": {"line": 1, "column": 5}
}
}
Notes for Developers¶
- The API automatically validates and pretty-prints JSON decoded from Base64 input.
- For large files or remote URLs, use asynchronous mode (
x-source-type: urlorx-source-type: file). - Every response includes a unique
request_idfor tracking and logging. - Async jobs can be monitored via the
/jobs/{job_id}endpoint. - Output files are temporarily stored and accessible via secure download links.
- Ensure file extensions comply with allowed types (
.txt,.log). - Rate limits and size limits depend on the user's plan configuration.