Skip to content

JSON to Pydantic Model API

Overview

Infers Pydantic v2 model classes from a JSON example.

Endpoint

POST https://api.apidatatools.com/json-to-pydantic-model-api

Authentication and input modes

Include x-api-key: YOUR_API_KEY. Supports body, url, and file through x-source-type; body is the default. Accepted extensions are .txt, .json, and .log.

Headers

Header Required Default Description
x-root-name No Root Root model class name.

curl example

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

Result

Produces a .py file importing BaseModel, Field, and RootModel from Pydantic. Invalid Python property names are normalized and retain their JSON name through Field(alias=...).

URL and file modes

curl --request POST --url https://api.apidatatools.com/json-to-pydantic-model-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-pydantic-model-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"}'

Success and async process

Body mode returns HTTP 200 with a temporary .py file and preview. URL/file mode returns HTTP 202 with job_id and status_url. Poll with the same API key. Queued/processing responses include message and retry_after; success includes result.file and result.preview; failure includes error.code, message, and details.

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

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 URL/file, worker, and status errors include INVALID_BODY, INVALID_FILE_EXTENSION, FILE_TOO_LARGE, DOWNLOAD_FAILED, UPLOAD_FAILED, INVALID_JOB_ID, JOB_NOT_FOUND, FORBIDDEN, and DDB_ERROR.

Notes

Honor retry_after; output retention and limits depend on your plan.