Skip to content

JSON to TypeScript API

Overview

Infers TypeScript interfaces and types from a JSON example.

Endpoint

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

Authentication

Include x-api-key: YOUR_API_KEY.

Input modes

Supports body (synchronous), url, and file (asynchronous).

Headers

Header Required Default Description
x-api-key Yes — API key.
x-source-type No body Input mode.
x-root-name No Root Name for the root interface or type. Non-alphanumeric separators are converted to PascalCase.

Accepted file extensions

.txt, .json, and .log.

curl example

curl -X POST 'https://api.apidatatools.com/json-to-typescript-api' \\
  -H 'x-api-key: YOUR_API_KEY' \\
  -H 'x-root-name: User' \\
  --data-raw '{"id":1,"name":"Ada","roles":["admin"]}'

Result

Produces a .ts file with content type text/typescript. Arrays containing differing JSON types are represented with union element types.

URL and file mode examples

curl --request POST --url https://api.apidatatools.com/json-to-typescript-api \
  --header 'x-api-key: YOUR_API_KEY' --header 'x-source-type: url' \
  --header 'x-root-name: User' --header 'Content-Type: application/json' \
  --data '{"url":"https://example.com/input.json"}'
curl --request POST --url https://api.apidatatools.com/json-to-typescript-api \
  --header 'x-api-key: YOUR_API_KEY' --header 'x-source-type: file' \
  --header 'x-root-name: User' --header 'Content-Type: application/json' \
  --data '{"file":"S3_KEY_RETURNED_BY_THE_UPLOAD_WORKFLOW"}'

The URL must be public and reachable. File mode requires the exact key returned by upload. Tool option headers are retained for worker processing.

Success and async process

Body mode returns HTTP 200 with a temporary .ts file URL and preview. URL/file mode returns HTTP 202:

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

Poll GET https://api.apidatatools.com/jobs/JOB_ID with the same API key. queued and processing include message and retry_after. success includes result.file and result.preview; failed includes error.code, error.message, and error.details.

Error handling

HTTP status Error codes
400 INVALID_SOURCE_TYPE, INVALID_BODY_ENCODING, EMPTY_BODY, INVALID_JSON, INVALID_JSON_ENCODING, JSON_TOO_DEEP
401 UNAUTHORIZED
404 USER_NOT_FOUND, UNKNOWN_FUNCTION
413 PAYLOAD_TOO_LARGE
429 QUOTA_EXCEEDED, RATE_LIMITED
500 PLAN_NOT_FOUND, AUTH_ERROR, INTERNAL_ERROR

Async submission can return INVALID_BODY, URL/file validation errors, FILE_TOO_LARGE, CONFIG_ERROR, or PLAN_CONFIG_ERROR. Processing can report INVALID_JOB, DOWNLOAD_FAILED, UPLOAD_FAILED, or tool errors. Status errors include INVALID_JOB_ID, JOB_NOT_FOUND, FORBIDDEN, and DDB_ERROR.

Notes

Honor retry_after. Plan limits govern input sizes and retention. Output URLs are temporary.