Skip to content

JSON Formatter API Documentation

Overview

The JSON Formatter API validates and pretty-prints JSON content.
It supports three input modes: - Body Mode: Send raw JSON text directly in the request body. - URL Mode: Provide a remote file URL containing JSON data. - File Mode: Reference a previously uploaded file stored in the system.

The API returns a formatted JSON file with customizable indentation via headers.


Endpoint (POST)

POST https://api.apidatatools.com/json-formatter-api

Headers

Header Description Example
Content-Type Must be application/json for body input application/json
x-source-type Defines input mode: body, url, or file body
x-tab-space Optional. Number of spaces for indentation (default: 1) 2
x-api-key Your API key for authentication Yes

Accepted File Extensions

This tool accepts the following file extensions for URL or File mode:

.txt, .json, .log


Input Example (Body Mode)

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

Input Example (URL Mode)

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

Input Example (File Mode)

{
  "file": "user/uploads/upl_abc123/sample.json"
}

Example Request

Synchronous (Body Input)

curl -X POST "https://api.apidatatools.com/json-formatter-api" \
  -H "Content-Type: application/json" \
  -H "x-source-type: body" \
  -H "x-tab-space: 2" \
  -H "x-api-key: YOUR_API_KEY" \
  -d '{"name":"John","age":30,"skills":["Python","API Development"]}'

Asynchronous (Remote File URL)

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

Asynchronous (Input File)

curl -X POST "https://api.apidatatools.com/json-formatter-api" \
  -H "Content-Type: application/json" \
  -H "x-source-type: file" \
  -H "x-tab-space: 2" \
  -H "x-api-key: YOUR_API_KEY" \
  -d '{"file":"user/uploads/upl_abc123/sample.json"}'

Example Response

Successful (Body Mode)

{
  "status": "success",
  "request_id": "req_12345",
  "file": "https://downloads.apidatatools.com/apidatatools_convert_abcd1234.json",
  "preview": "{\n  \"name\": \"John\",\n  \"age\": 30,\n  \"skills\": [\n    \"Python\",\n    \"API Development\"\n  ]\n}"
}

Async Job Accepted (URL or File Mode)

{
  "status": "accepted",
  "job_id": "job_67890",
  "status_url": "https://api.apidatatools.com/jobs/job_67890",
  "request_id": "req_12345"
}

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.","line":2,"column":10}}
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 size 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 Remote URL cannot be reached {"status":"error","error":"URL_UNREACHABLE","details":{"message":"Could not reach URL."}}
URL_NOT_OK 400 URL returned non-200 HTTP 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":"File exceeds plan limit."}}
INVALID_FILE_EXTENSION 400 Unsupported file extension {"status":"error","error":"INVALID_FILE_EXTENSION","details":{"message":"Invalid or unsupported file extension."}}
FILE_UNAVAILABLE 400 File not accessible {"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

To check the status of an asynchronous job (URL or File mode):

Endpoint

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

Example Status Response for Async

Queued

Queued

{
  "job_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "status": "queued",
  "message": "Your job is being processed.",
  "retry_after": 2
}

Success

{
  "job_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "status": "success",
  "created_at": 1712345678,
  "updated_at": 1712345689,
  "result": {
    "request_id": "b7f9e1c3-8d2a-4e6f-9a3c-0d8e7f2b9a1f",
    "status": "success",
    "file": "https://downloads.apidatatools.com/apidatatools_convert_abc123.json",
    "preview": "{\n  \"name\": \"John\",\n  \"age\": 30,\n  \"skills\": [\n    \"Python\",\n    \"API\",\n    \"AWS\"\n  ]\n}"
  }
}

Failed

{
  "job_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "status": "failed",
  "error": {
    "code": "INVALID_JSON",
    "message": "JSON validation failed.",
    "details": {
      "line": 2,
      "column": 5
    }
  }
}

Notes for Developers

  • The tool supports all three modes: body, url, and file.
  • For asynchronous operations (url or file mode), a job ID is returned with a status_url for polling.
  • The preview field in synchronous responses is limited to 100 KB.
  • The output file is stored temporarily and accessible via a secure download link.
  • Ensure proper error handling and header configuration when integrating this API.