JSON Escape API Documentation¶
Overview¶
The JSON Escape API validates a JSON input and returns a properly escaped JSON string literal.
It supports Body, URL, and File input modes.
When using URL or File mode, the request is processed asynchronously, and a job ID is returned for status tracking.
This API ensures that the input JSON is valid and then escapes it using standard JSON encoding rules.
The output is a valid JSON string containing the escaped version of the original JSON text.
Endpoint (POST)¶
POST https://api.apidatatools.com/json-escape-api
Headers¶
| Header | Description | Required | Example |
|---|---|---|---|
Content-Type | Input content type | Yes | application/json |
x-source-type | Input source type: body, url, or file | Optional (default: body) | url |
x-api-key | Your API key for authentication | Yes | abcd1234xyz |
Accepted File Extensions¶
This tool accepts the following file extensions when using URL or File mode:
.txt, .json, .log
Input Example (Body Mode)¶
{
"name": "John",
"age": 30,
"city": "New York"
}
Input Example (URL Mode)¶
{
"url": "https://example.com/sample.json"
}
Input Example (File Mode)¶
{
"file": "user_uploads/sample.json"
}
Example Request¶
Synchronous (Body Input)¶
curl -X POST "https://api.apidatatools.com/json-escape-api" \
-H "Content-Type: application/json" \
-H "x-source-type: body" \
-H "x-api-key: YOUR_API_KEY" \
-d '{"name": "John", "age": 30}'
Asynchronous (Remote File URL)¶
curl -X POST "https://api.apidatatools.com/json-escape-api" \
-H "Content-Type: application/json" \
-H "x-source-type: url" \
-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-escape-api" \
-H "Content-Type: application/json" \
-H "x-source-type: file" \
-H "x-api-key: YOUR_API_KEY" \
-d '{"file": "uploads/user123/data.json"}'
Example Response¶
Successful (Body Mode)¶
{
"status": "success",
"request_id": "a1b2c3d4e5",
"file": "https://downloads.apidatatools.com/apidatatools_convert_abc123.json",
"preview": "\"{\\\"name\\\": \\\"John\\\", \\\"age\\\": 30}\""
}
Async Job Accepted¶
{
"status": "accepted",
"job_id": "job-123456789",
"status_url": "https://api.apidatatools.com/jobs/job-123456789",
"request_id": "a1b2c3d4e5"
}
Error Handling¶
| Error Code | HTTP Status | Description | Example |
|---|---|---|---|
INVALID_JSON | 400 | Input JSON is invalid or malformed | {"status":"error","error":"INVALID_JSON","details":{"message":"JSON validation failed."}} |
JSON_ESCAPE_FAILED | 400 | Failed to escape JSON string | {"status":"error","error":"JSON_ESCAPE_FAILED","details":{"message":"Failed to escape JSON string."}} |
INVALID_BODY_ENCODING | 400 | Body could not be base64-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 is missing or invalid | {"status":"error","error":"INVALID_URL","details":{"message":"URL must be valid http/https."}} |
URL_UNREACHABLE | 400 | Remote URL cannot 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."}} |
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 internal 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 following endpoint:
GET https://api.apidatatools.com/jobs/{job_id}
Example Status Response for Async¶
Queued¶
{
"job_id": "job-123456789",
"status": "queued",
"created_at": 1712345678,
"updated_at": 1712345678,
"message": "Your job is being processed.",
"retry_after": 2
}
Success¶
{
"job_id": "job-123456789",
"status": "success",
"created_at": 1712345678,
"updated_at": 1712345689,
"result": {
"request_id": "a1b2c3d4e5",
"status": "success",
"file": "https://downloads.apidatatools.com/apidatatools_convert_abc123.json",
"preview": "\"{\\\"name\\\":\\\"John\\\",\\\"age\\\":30}\""
}
}
Failed¶
{
"job_id": "job-123456789",
"status": "failed",
"created_at": 1712345678,
"updated_at": 1712345689,
"error": {
"code": "INVALID_JSON",
"message": "JSON validation failed.",
"details": {
"line": 1,
"column": 5
}
}
}
Notes for Developers¶
- The API supports three modes:
body,url, andfile. - When
x-source-typeisurlorfile, the request is processed asynchronously. - The asynchronous response includes a
job_idand astatus_urlfor polling job status. - The
request_idis included in every response for traceability. - The preview field contains the first 100 KB of the escaped JSON string.
- The output file is stored securely and accessible via a temporary download link.