Skip to content

JSON to Base64 API Documentation

Overview

The JSON to Base64 API validates a JSON input and converts the original JSON text into a Base64-encoded string.
It ensures the JSON structure is valid before encoding and returns the encoded content as a downloadable .txt file.
This API supports synchronous (direct body) and asynchronous (remote URL or uploaded file) modes.


Endpoint (POST)

POST https://api.apidatatools.com/json-to-base64-api


Headers

Header Type Required Description
x-api-key string Yes Your API key for authentication
Content-Type string Yes Must be application/json
x-source-type string Optional Defines input source: body (default), url, or file

Accepted File Extensions

Mode Allowed Extensions
URL / File .txt, .json, .log

Input Example (Body Mode)

{
  "name": "John Doe",
  "age": 30,
  "skills": ["Python", "API", "AWS"]
}

Input Example (URL Mode)

{
  "url": "https://example.com/sample.json"
}

Input Example (File Mode)

{
  "file": "user_uploads/upl_1234567890abcdef/sample.json"
}

Example Request

Synchronous (Body Input)

curl -X POST "https://api.apidatatools.com/json-to-base64-api" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -H "x-source-type: body" \
  -d '{"name": "John Doe", "age": 30}'

Asynchronous (Remote File URL)

curl -X POST "https://api.apidatatools.com/json-to-base64-api" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -H "x-source-type: url" \
  -d '{"url": "https://example.com/sample.json"}'

Asynchronous (Input File)

curl -X POST "https://api.apidatatools.com/json-to-base64-api" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -H "x-source-type: file" \
  -d '{"file": "user_uploads/upl_1234567890abcdef/sample.json"}'

Example Response

Successful (Body Mode)

{
  "status": "success",
  "request_id": "b7c2e1d4-9a12-4b1a-9e8f-123456789abc",
  "file": "https://downloads.apidatatools.com/apidatatools_convert_abcdef1234567890.txt",
  "preview": "eyJuYW1lIjogIkpvaG4gRG9lIiwgImFnZSI6IDMwfQ=="
}

Async Job Accepted (URL or File Mode)

{
  "status": "accepted",
  "job_id": "a1b2c3d4-e5f6-7890-abcd-1234567890ef",
  "status_url": "https://api.apidatatools.com/jobs/a1b2c3d4-e5f6-7890-abcd-1234567890ef",
  "request_id": "b7c2e1d4-9a12-4b1a-9e8f-123456789abc"
}

Error Handling

Error Code HTTP Status Description Example
INVALID_JSON 400 Input is not valid JSON {"status":"error","error":"INVALID_JSON","details":{"message":"JSON validation failed."}}
BASE64_ENCODING_FAILED 400 Failed to encode JSON to Base64 {"status":"error","error":"BASE64_ENCODING_FAILED","details":{"message":"Failed to encode JSON to Base64."}}
INVALID_BODY_ENCODING 400 Request body could not be decoded {"status":"error","error":"INVALID_BODY_ENCODING","details":{"message":"Failed to base64-decode request body."}}
EMPTY_BODY 400 Request body is empty {"status":"error","error":"EMPTY_BODY","details":{"message":"Request body is empty."}}
PAYLOAD_TOO_LARGE 413 Body exceeds plan limit {"status":"error","error":"PAYLOAD_TOO_LARGE","details":{"message":"Request body exceeds limit."}}
INVALID_URL 400 URL missing or invalid {"status":"error","error":"INVALID_URL","details":{"message":"Missing or invalid 'url'."}}
URL_UNREACHABLE 400 URL cannot be reached {"status":"error","error":"URL_UNREACHABLE","details":{"message":"Could not reach URL."}}
URL_NOT_OK 400 URL returned non-200 response {"status":"error","error":"URL_NOT_OK","details":{"message":"URL returned HTTP 404, expected 200."}}
FILE_TOO_LARGE 413 File exceeds plan limit {"status":"error","error":"FILE_TOO_LARGE","details":{"message":"File exceeds plan limit."}}
INVALID_FILE_EXTENSION 400 File extension not supported {"status":"error","error":"INVALID_FILE_EXTENSION","details":{"message":"Invalid or unsupported file extension."}}
FILE_UNAVAILABLE 400 File not found or inaccessible {"status":"error","error":"FILE_UNAVAILABLE","details":{"message":"Could not access file."}}
INTERNAL_ERROR 500 Unexpected server error {"status":"error","error":"INTERNAL_ERROR","details":{"message":"Failed to process your request"}}

Async Job Status

Endpoint:
GET https://api.apidatatools.com/jobs/{job_id}

Example Status Response for Async

Queued or Processing

{
  "job_id": "a1b2c3d4-e5f6-7890-abcd-1234567890ef",
  "status": "queued",
  "message": "Your job is being processed.",
  "retry_after": 2,
  "created_at": 1712345678,
  "updated_at": 1712345678
}

Successful

{
  "job_id": "a1b2c3d4-e5f6-7890-abcd-1234567890ef",
  "status": "success",
  "created_at": 1712345678,
  "updated_at": 1712345690,
  "result": {
    "status": "success",
    "request_id": "b7c2e1d4-9a12-4b1a-9e8f-123456789abc",
    "file": "https://downloads.apidatatools.com/apidatatools_convert_abcdef1234567890.txt",
    "preview": "eyJuYW1lIjogIkpvaG4gRG9lIiwgImFnZSI6IDMwfQ=="
  }
}

Failed

{
  "job_id": "a1b2c3d4-e5f6-7890-abcd-1234567890ef",
  "status": "failed",
  "created_at": 1712345678,
  "updated_at": 1712345690,
  "error": {
    "code": "INVALID_JSON",
    "message": "JSON validation failed.",
    "details": {
      "message": "Expecting property name enclosed in double quotes",
      "line": 1,
      "column": 5
    }
  }
}

Notes for Developers

  • The API validates JSON strictly before encoding.
  • The Base64 output is generated from the original JSON text, not a reformatted version.
  • The output file is stored temporarily and accessible via the returned download URL.
  • For large files or remote URLs, use asynchronous mode (x-source-type: url or file).
  • Each response includes a unique request_id for traceability.
  • Use the status_url from the async response to poll job progress.