JSON Schema Generator API Documentation¶
Overview¶
The JSON Schema Generator API validates a JSON input and automatically generates a JSON Schema (Draft 2020-12) that describes the structure and data types of the provided JSON.
It supports three input modes:
- Body Mode (direct JSON text)
- URL Mode (remote file URL)
- File Mode (uploaded file from storage)
This API returns a downloadable JSON Schema file and a preview snippet for quick inspection.
Endpoint (POST)¶
POST https://api.apidatatools.com/json-schema-generator-api
Headers¶
| Header | Description | Required | Example |
|---|---|---|---|
Content-Type | Must be application/json for body input | Yes | application/json |
x-source-type | Defines input mode: 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 types for URL or File mode:
.txt, .json, .log
Input Example (Body Mode)¶
{
"name": "John Doe",
"age": 30,
"is_active": true,
"roles": ["admin", "editor"]
}
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-schema-generator-api" \
-H "Content-Type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
-H "x-source-type: body" \
-d '{"name":"John","age":25,"skills":["python","sql"]}'
Asynchronous (Remote File URL)¶
curl -X POST "https://api.apidatatools.com/json-schema-generator-api" \
-H "Content-Type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
-H "x-source-type: url" \
-d '{"url":"https://example.com/data.json"}'
Asynchronous (Input File)¶
curl -X POST "https://api.apidatatools.com/json-schema-generator-api" \
-H "Content-Type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
-H "x-source-type: file" \
-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": "{\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n \"type\": \"object\",\n \"properties\": {\n \"name\": {\"type\": \"string\"},\n \"age\": {\"type\": \"integer\"},\n \"skills\": {\"type\": \"array\"}\n }\n}"
}
Async Job Accepted¶
{
"status": "accepted",
"job_id": "job-12345-xyz",
"status_url": "https://api.apidatatools.com/jobs/job-12345-xyz",
"request_id": "req-67890"
}
Error Handling¶
| Error Code | HTTP Status | Description | Example |
|---|---|---|---|
INVALID_JSON | 400 | Input JSON is malformed or cannot be parsed | {"status":"error","error":"INVALID_JSON","details":{"message":"JSON validation failed."}} |
SCHEMA_GENERATION_FAILED | 400 | Failed to infer schema structure | {"status":"error","error":"SCHEMA_GENERATION_FAILED","details":{"message":"Failed to generate JSON Schema."}} |
SCHEMA_SERIALIZATION_FAILED | 400 | Failed to serialize schema output | {"status":"error","error":"SCHEMA_SERIALIZATION_FAILED","details":{"message":"Failed to serialize JSON Schema to JSON."}} |
FILE_TOO_LARGE | 413 | File exceeds plan limit | {"status":"error","error":"FILE_TOO_LARGE","details":{"message":"Remote file exceeds plan limit."}} |
INVALID_URL | 400 | Provided URL is invalid or unreachable | {"status":"error","error":"INVALID_URL","details":{"message":"URL must be valid http/https."}} |
URL_UNREACHABLE | 400 | Could not reach the remote URL | {"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 | Unsupported file extension | {"status":"error","error":"INVALID_FILE_EXTENSION","details":{"message":"Invalid or unsupported file extension"}} |
INVALID_SOURCE_TYPE | 400 | Invalid x-source-type header value | {"status":"error","error":"INVALID_SOURCE_TYPE","details":{"message":"Must be 'url' or 'file'."}} |
PAYLOAD_TOO_LARGE | 413 | Body exceeds allowed size | {"status":"error","error":"PAYLOAD_TOO_LARGE","details":{"message":"Request body exceeds limit."}} |
INTERNAL_ERROR | 500 | Unexpected internal failure | {"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), use:
GET https://api.apidatatools.com/jobs/{job_id}
Example Status Response for Async¶
Queued¶
{
"job_id": "job-12345-xyz",
"status": "queued",
"message": "Your job is being processed.",
"retry_after": 2
}
Success¶
{
"job_id": "job-12345-xyz",
"status": "success",
"created_at": 1712345678,
"updated_at": 1712345690,
"result": {
"request_id": "req-67890",
"status": "success",
"file": "https://downloads.apidatatools.com/apidatatools_convert_abc123.json",
"preview": "{...}"
}
}
Failed¶
{
"job_id": "job-12345-xyz",
"status": "failed",
"error": {
"code": "INVALID_JSON",
"message": "JSON validation failed.",
"details": {"line": 2, "column": 10}
}
}
Notes for Developers¶
- The API automatically infers JSON Schema types (
string,number,integer,boolean,array,object,null). - Arrays with mixed types are represented using
anyOfin the schema. - The top-level schema includes
$schemametadata for Draft 2020-12 compliance. - For large files or remote URLs, use asynchronous mode (
x-source-type: urlorx-source-type: file). - Each response includes a unique
request_idfor tracking and debugging. - The preview field contains up to 100 KB of schema content for quick inspection.
- The generated schema file is stored securely and expires based on your plan’s retention policy.
- To monitor async jobs, use the provided
status_urlendpoint until completion.