Skip to content

XML to JSON API Documentation

Overview

The XML to JSON API converts well-formed XML content into a structured, pretty-printed JSON format.
It validates the XML input for correctness and safely parses it before generating the JSON output.
This API supports Body, URL, and File input modes, allowing both synchronous and asynchronous operations.


Endpoint (POST)

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


Headers

Header Description Required Example
Content-Type Defines the input content type. Yes application/xml
x-source-type Specifies input mode: body, url, or file. Optional body
x-tab-space Controls JSON indentation (default: 2). Optional 4
x-api-key Your API key for authentication Yes abcd1234xyz

Accepted File Extensions

This tool accepts the following input file extensions:

  • .txt
  • .xml
  • .log

Input Example (Body Mode)

<note><to>User</to><from>API</from><message>Hello World</message></note>

Input Example (URL Mode)

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

Input Example (File Mode)

{
  "file": "user_uploads/sample.xml"
}

Example Request

Synchronous (Body Input)

curl -X POST "https://api.apidatatools.com/xml-to-json-api" \
  -H "Content-Type: application/xml" \
  -H "x-source-type: body" \
  -H "x-api-key: YOUR_API_KEY" \
  -d "<note><to>User</to><from>API</from><message>Hello World</message></note>"

Asynchronous (Remote File URL)

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

Asynchronous (Input File)

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

Example Response

Successful (Body Mode)

{
  "status": "success",
  "request_id": "a1b2c3d4e5",
  "file": "https://downloads.apidatatools.com/apidatatools_convert_abc123.json",
  "preview": "{\n  \"note\": {\n    \"to\": \"User\",\n    \"from\": \"API\",\n    \"message\": \"Hello World\"\n  }\n}"
}

Async Job Accepted

{
  "status": "accepted",
  "job_id": "job-1234567890",
  "status_url": "https://api.apidatatools.com/jobs/job-1234567890",
  "request_id": "a1b2c3d4e5"
}

Error Handling

Error Code HTTP Status Description Example
INVALID_XML 400 XML validation or parsing failed. {"status":"error","error":"INVALID_XML","details":{"message":"XML parsing failed.","line":5,"column":10}}
JSON_SERIALIZATION_FAILED 400 Failed to convert XML to JSON. {"status":"error","error":"JSON_SERIALIZATION_FAILED","details":{"message":"Failed to serialize XML to JSON."}}
INVALID_BODY_ENCODING 400 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."}}
FILE_TOO_LARGE 413 File exceeds allowed size. {"status":"error","error":"FILE_TOO_LARGE","details":{"message":"Remote file exceeds plan limit."}}
INVALID_URL 400 URL is missing or invalid. {"status":"error","error":"INVALID_URL","details":{"message":"URL must be valid http/https."}}
URL_UNREACHABLE 400 Remote URL could not be reached. {"status":"error","error":"URL_UNREACHABLE","details":{"message":"Could not reach URL."}}
URL_NOT_OK 400 Remote URL returned non-200 status. {"status":"error","error":"URL_NOT_OK","details":{"message":"URL returned HTTP 404, expected 200."}}
INVALID_FILE_EXTENSION 400 File extension not supported. {"status":"error","error":"INVALID_FILE_EXTENSION","details":{"message":"Extension '.exe' is not allowed for 'xml-to-json-api'."}}
FILE_UNAVAILABLE 400 File not accessible in storage. {"status":"error","error":"FILE_UNAVAILABLE","details":{"message":"Could not access file."}}
PAYLOAD_TOO_LARGE 413 Body exceeds plan limit. {"status":"error","error":"PAYLOAD_TOO_LARGE","details":{"message":"Request body exceeds limit."}}
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-1234567890",
  "status": "queued",
  "message": "Your job is being processed.",
  "retry_after": 2
}

Success

{
  "job_id": "job-1234567890",
  "status": "success",
  "created_at": 1712345678,
  "updated_at": 1712345689,
  "result": {
    "request_id": "a1b2c3d4e5",
    "status": "success",
    "file": "https://downloads.apidatatools.com/apidatatools_convert_abc123.json",
    "preview": "{\n  \"note\": {\n    \"to\": \"User\",\n    \"from\": \"API\",\n    \"message\": \"Hello World\"\n  }\n}"
  }
}

Failed

{
  "job_id": "job-1234567890",
  "status": "failed",
  "error": {
    "code": "INVALID_XML",
    "message": "XML parsing failed.",
    "details": {
      "line": 5,
      "column": 10
    }
  }
}

Notes for Developers

  • The API automatically validates XML using a secure parser before conversion.
  • The output JSON is pretty-printed with indentation controlled by the x-tab-space header.
  • For asynchronous operations (url or file mode), a job ID is returned immediately with a 202 Accepted status.
  • Use the Status API to poll job progress or retrieve results.
  • The request_id is included in every response for traceability.
  • Output files are securely stored and accessible via a temporary download link.
  • Ensure that input XML files are well-formed and within plan size limits.
  • Supported modes: body, url, file.