Prompt
OCR to JSON API for documents
Latest observation
Oct 11, 2026
OpenAI APIWeb search: off
Here’s a practical OCR-to-JSON API design for document processing.
What it does
- Accepts document uploads: PDF, JPG, PNG, TIFF
- Runs OCR to extract text
- Returns structured JSON with:
- full text
- page data
- word/line boxes
- confidence scores
- optional fields like tables, key-value pairs, and language
Example API endpoints
1) Upload document
POST /v1/ocr
Request
Content-Type: multipart/form-data
Form fields
file: document fileoutput_format:json(default)detect_tables:true|falsedetect_key_values:true|falselanguage: optional, e.g.eng,spa,auto
Response
{
"job_id": "ocr_12345",
"status": "queued"
}
2) Check job status
GET /v1/ocr/{job_id}
Response
{
"job_id": "ocr_12345",
"status": "completed"
}
3) Get OCR result
GET /v1/ocr/{job_id}/result
Response
{
"job_id": "ocr_12345",
"status": "completed",
"document": {
"filename": "invoice.pdf",
"page_count": 2,
"language": "eng"
},
"pages": [
{
"page नंबर": 1,
"width": 2480,
"height": 3508,
"text": "Invoice #123 ...",
"lines": [
{
"text": "Invoice #123",
"confidence": 0.98,
"bbox": [120, 80, 420, 120]
}
],
"words": [
{
"text": "Invoice",
"confidence": 0.99,
"bbox": [120, 80, 220, 120]
}
]
}
]
}
Recommended JSON schema
A good OCR JSON structure:
{
"job_id": "string",
"status": "string",
"document": {
"filename": "string",
"mime_type": "string",
"page_count": "integer",
"language": "string"
},
"pages": [
{
"page_number": "integer",
"width": "integer",
"height": "integer",
"rotation": "integer",
"text": "string",
"blocks": [
{
"type": "paragraph|table|title|list",
"text": "string",
"confidence": "number",
"bbox": [0, 0, 0, 0]
}
],
"lines": [
{
"text": "string",
"confidence": "number",
"bbox": [0, 0, 0, 0]
}
],
"words": [
{
"text": "string",
"confidence": "number",
"bbox": [0, 0, 0, 0]
}
]
}
],
"tables": [
{
"page_number": 1,
"bbox": [0, 0, 0, 0],
"rows": [
["cell1", "cell2"]
]
}
],
"key_values": [
{
"key": "Invoice Number",
"value": "12345",
"confidence": 0.97
}
]
}
Error response example
{
"error": {
"code": "unsupported_file_type",
"message": "Only PDF, PNG, JPG, TIFF are supported."
}
}
Optional features to add
- Async processing for large files
- Webhook callback when OCR finishes
- Searchable text output
- Bounding boxes in normalized coordinates
- Table extraction
- Form extraction
- Handwriting recognition
- Multi-language OCR
- Page image thumbnails
If you want to build it
A common stack:
- API: FastAPI / Express / Flask
- OCR engine: Tesseract, PaddleOCR, AWS Textract, Google Vision, Azure OCR
- Storage: S3 / local blob store
- Queue: Celery / Redis / RabbitMQ
- DB: PostgreSQL for jobs and metadata
If you want, I can also give you:
- a full OpenAPI spec,
- a FastAPI implementation, or
- a JSON schema for the OCR response.