JSON to YAML API Documentation¶
Overview¶
The JSON to YAML API converts valid JSON input into a well-formatted YAML document.
It supports three input modes:
- Body Mode – Direct JSON text in the request body (synchronous).
- URL Mode – Remote file URL containing JSON (asynchronous).
- File Mode – Uploaded file reference (asynchronous).
The API validates the JSON structure before conversion and returns a downloadable YAML file link.
Endpoint (POST)¶
POST https://api.apidatatools.com/json-to-yaml-api
Headers¶
| Header | Description | Required | Example |
|---|---|---|---|
Content-Type | MIME type of the request body | Yes | application/json |
x-api-key | Your API key for authentication | Yes | abcd1234xyz |
x-source-type | Input mode: body, url, or file | Optional (default: body) | url |
Accepted File Extensions¶
| Mode | Allowed Extensions |
|---|---|
| URL / File | .txt, .json, .log |
Input Example (Body Mode)¶
{
"name": "John Doe",
"age": 30,
"skills": ["Python", "YAML", "JSON"]
}
Input Example (URL Mode)¶
{
"url": "https://example.com/sample.json"
}
Input Example (File Mode)¶
{
"file": "user_uploads/12345/sample.json"
}
Example Request¶
Synchronous (Body Input)¶
curl -X POST "https://api.apidatatools.com/json-to-yaml-api" \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "x-source-type: body" \
-d '{"name": "John", "age": 25}'
Asynchronous (Remote File URL)¶
curl -X POST "https://api.apidatatools.com/json-to-yaml-api" \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "x-source-type: url" \
-d '{"url": "https://example.com/data.json"}'
Asynchronous (Input File)¶
curl -X POST "https://api.apidatatools.com/json-to-yaml-api" \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "x-source-type: file" \
-d '{"file": "uploads/user123/data.json"}'
Example Response¶
Successful (Body Mode)¶
Status Code: 200 OK
{
"status": "success",
"request_id": "c9e8f2b1-1234-4bcd-9aef-5678abcd9012",
"file": "https://downloads.apidatatools.com/apidatatools_convert_abc123.yaml",
"preview": "name: John\nage: 25\n"
}
Async Job Accepted¶
Status Code: 202 Accepted
{
"status": "accepted",
"job_id": "b7e2a3c4-5678-4def-9012-3456abcdef78",
"status_url": "https://api.apidatatools.com/jobs/b7e2a3c4-5678-4def-9012-3456abcdef78",
"request_id": "a1b2c3d4-5678-90ef-1234-56789abcdef0"
}
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."}} |
YAML_CONVERSION_FAILED | 400 | Failed to convert JSON to YAML | {"status":"error","error":"YAML_CONVERSION_FAILED","details":{"message":"Failed to convert JSON to YAML."}} |
INVALID_URL | 400 | URL missing or invalid | {"status":"error","error":"INVALID_URL","details":{"message":"Missing or invalid 'url'."}} |
URL_UNREACHABLE | 400 | URL could not be reached | {"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, expected 200."}} |
FILE_TOO_LARGE | 413 | File exceeds plan limit | {"status":"error","error":"FILE_TOO_LARGE","details":{"message":"Remote file exceeds plan limit."}} |
INVALID_FILE_EXTENSION | 400 | Unsupported file extension | {"status":"error","error":"INVALID_FILE_EXTENSION","details":{"message":"Invalid or unsupported file extension"}} |
EMPTY_BODY | 400 | Request body is empty | {"status":"error","error":"EMPTY_BODY","details":{"message":"Request body is empty."}} |
PAYLOAD_TOO_LARGE | 413 | Body exceeds allowed size | {"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¶
Endpoint:
GET https://api.apidatatools.com/jobs/{job_id}
Headers:
x-api-key: YOUR_API_KEY
Example Status Response for Async¶
Pending¶
{
"job_id": "b7e2a3c4-5678-4def-9012-3456abcdef78",
"status": "queued",
"message": "Your job is being processed.",
"retry_after": 2
}
Success¶
{
"job_id": "b7e2a3c4-5678-4def-9012-3456abcdef78",
"status": "success",
"created_at": 1712345678,
"updated_at": 1712345690,
"result": {
"status": "success",
"request_id": "b7f9e8a2-4d1b-4a3c-9e2e-123456789abc",
"file": "https://downloads.apidatatools.com/apidatatools_convert_abc123.yaml",
"preview": "name: John\nage: 25\n"
}
}
Failed¶
{
"job_id": "b7e2a3c4-5678-4def-9012-3456abcdef78",
"status": "failed",
"error": {
"code": "INVALID_JSON",
"message": "JSON validation failed.",
"details": {
"message": "Expecting property name enclosed in double quotes",
"line": 1,
"column": 2
}
}
}
Notes for Developers¶
- The API automatically validates JSON before conversion.
- The YAML output preserves key order and uses block-style formatting.
- The preview field in responses is truncated to the first 100 KB of the YAML output.
- For asynchronous operations (
urlorfilemode), use the providedstatus_urlto poll job status. - Each response includes a unique
request_idfor traceability. - Ensure your plan limits allow for the file size you are submitting.
- The output file is stored temporarily and accessible via the returned download URL.