Skip to content

JSON to XML API Documentation

Overview

The JSON to XML API converts valid JSON input into a well-structured, pretty-printed XML document.
It supports three input modes:

  • Body Mode – Direct JSON text in the request body.
  • URL Mode – Remote JSON file accessible via HTTP/HTTPS.
  • File Mode – Pre-uploaded file stored in the system.

The API validates the JSON structure before conversion and returns the XML output as a downloadable file.
For asynchronous operations (URL or File mode), a job ID is returned to track conversion progress.


Endpoint (POST)

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

Headers

Header Description Required Example
Content-Type Must be application/json for body mode Yes application/json
x-root-name Custom XML root element name Optional x-root-name: dataRoot
x-source-type Input source type: body, url, or file Optional (defaults to body) x-source-type: url
x-api-key Your API key for authentication Yes abcd1234xyz

Accepted File Extensions

This tool accepts the following file extensions for input:

.txt, .json, .log


Input Example (Body Mode)

{
  "name": "John Doe",
  "age": 30,
  "skills": ["Python", "XML", "JSON"]
}

Input Example (URL Mode)

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

Input Example (File Mode)

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

Example Request

Synchronous (Body Input)

curl -X POST "https://api.apidatatools.com/json-to-xml-api" \
  -H "Content-Type: application/json" \
  -H "x-root-name: userData" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "x-source-type: body" \
  -d '{"name": "John", "age": 25, "skills": ["Python", "XML"]}'

Asynchronous (Remote File URL)

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

Asynchronous (Input File)

curl -X POST "https://api.apidatatools.com/json-to-xml-api" \
  -H "Content-Type: application/json" \
  -H "x-source-type: file" \
  -H "x-root-name: userData" \
  -H "x-api-key: YOUR_API_KEY" \
  -d '{"file": "uploads/user123/data.json"}'

Example Response

Successful (Body Mode)

{
  "status": "success",
  "request_id": "b7f9e8a2-4d1b-4a3c-9e2e-123456789abc",
  "file": "https://downloads.apidatatools.com/apidatatools_convert_abc123.xml",
  "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<userData>\n  <name>John</name>\n  <age>25</age>\n  <skills>\n    <item0>Python</item0>\n    <item1>XML</item1>\n  </skills>\n</userData>"
}

Async Job Accepted

{
  "status": "accepted",
  "job_id": "job_1234567890abcdef",
  "status_url": "https://api.apidatatools.com/jobs/job_1234567890abcdef",
  "request_id": "b7f9e8a2-4d1b-4a3c-9e2e-123456789abc"
}

Error Handling

Error Code HTTP Status Description Example
INVALID_JSON 400 JSON validation failed {"status":"error","error":"INVALID_JSON","details":{"message":"Expecting value at line 1 column 1"}}
XML_CONVERSION_FAILED 400 Failed to convert JSON to XML {"status":"error","error":"XML_CONVERSION_FAILED","details":{"message":"Unexpected structure"}}
INVALID_BODY_ENCODING 400 Failed to decode base64 body {"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 5120KB limit"}}
INVALID_URL 400 Invalid or missing URL {"status":"error","error":"INVALID_URL","details":{"message":"Missing or invalid 'url'."}}
URL_UNREACHABLE 400 Could not reach URL {"status":"error","error":"URL_UNREACHABLE","details":{"message":"Could not reach URL"}}
URL_NOT_OK 400 URL returned non-200 status {"status":"error","error":"URL_NOT_OK","details":{"message":"URL returned HTTP 404"}}
FILE_TOO_LARGE 413 File exceeds plan limit {"status":"error","error":"FILE_TOO_LARGE","details":{"message":"File exceeds plan limit"}}
INVALID_FILE_EXTENSION 400 Unsupported file extension {"status":"error","error":"INVALID_FILE_EXTENSION","details":{"message":"Extension '.exe' is not allowed"}}
INVALID_SOURCE_TYPE 400 Must be url or file {"status":"error","error":"INVALID_SOURCE_TYPE","details":{"message":"Must be 'url' or 'file'."}}
INTERNAL_ERROR 500 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, use the Status API:

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

Example Status Response for Async

Queued

{
  "job_id": "job_1234567890abcdef",
  "status": "queued",
  "message": "Your job is being processed.",
  "retry_after": 2
}

Success

{
  "job_id": "job_1234567890abcdef",
  "status": "success",
  "created_at": 1712345678,
  "updated_at": 1712345690,
  "result": {
    "request_id": "b7f9e8a2-4d1b-4a3c-9e2e-123456789abc",
    "status": "success",
    "file": "https://downloads.apidatatools.com/apidatatools_convert_abc123.xml",
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<root>...</root>"
  }
}

Failed

{
  "job_id": "job_1234567890abcdef",
  "status": "failed",
  "error": {
    "code": "INVALID_JSON",
    "message": "JSON validation failed.",
    "details": {
      "line": 1,
      "column": 2
    }
  }
}

Notes for Developers

  • The API automatically validates JSON before conversion.
  • The optional header x-root-name customizes the root XML tag.
  • For large files or remote URLs, use asynchronous mode (x-source-type: url or x-source-type: file).
  • Async jobs return a job_id and status_url for tracking.
  • The preview field in responses contains the first 100 KB of the XML output.
  • Always include request_id in logs or client-side tracking for troubleshooting.
  • The output file is stored securely and expires based on your plan’s retention policy.