Prompt

How do I process receipts with OCR and return JSON?

Artificial Intelligence / Computer Vision1 observationLast seen Oct 11, 2026

Latest observation

Oct 11, 2026OpenAI APIWeb search: off

To process receipts with OCR and return JSON, the typical pipeline is:

  1. Capture the receipt image

    • Accept image/PDF upload from user.
    • Preprocess if needed: deskew, denoise, increase contrast, crop.
  2. Run OCR

    • Use an OCR engine such as:
      • Tesseract (open source)
      • Google Cloud Vision
      • AWS Textract
      • Azure Form Recognizer
    • Extract raw text and, if available, bounding boxes/coordinates.
  3. Parse the text into fields

    • Identify common receipt fields:
      • merchant name
      • date
      • total
      • subtotal
      • tax
      • currency
      • payment method
      • line items
    • Use rules, regex, or an LLM/post-processing model to map raw OCR text into structured data.
  4. Validate and normalize

    • Convert dates to ISO format
    • Normalize currency symbols
    • Convert amounts to numbers
    • Check totals/tax consistency if possible
  5. Return JSON

    • Respond with a structured object.

Example JSON:

{
  "merchant_name": "Starbucks",
  "date": "2026-10-11",
  "currency": "USD",
  "subtotal": 8.75,
  "tax": 0.70,
  "total": 9.45,
  "payment_method": "Visa",
  "items": [
    {
      "description": "Latte",
      "quantity": 1,
      "unit_price": 4.25,
      "line_total": 4.25
    },
    {
      "description": "Bagel",
      "quantity": 1,
      "unit_price": 4.50,
      "line_total": 4.50
    }
  ],
  "raw_text": "..."
}

Simple Python example with OCR + JSON extraction

import re
import json
from PIL import Image
import pytesseract

def parse_receipt_text(text):
    result = {
        "merchant_name": None,
        "date": None,
        "currency": None,
        "subtotal": None,
        "tax": None,
        "total": None,
        "raw_text": text
    }

    # Date example: 10/11/2026
    date_match = re.search(r'(\d{1,2}[/-]\d{1,2}[/-]\d{2,4})', text)
    if date_match:
        result["date"] = date_match.group(1)

    # Total example
    total_match = re.search(r'Total\s*\$?(\d+\.\d{2})', text, re.IGNORECASE)
    if total_match:
        result["total"] = float(total_match.group(1))
        result["currency"] = "USD"

    # Merchant: first non-empty line
    lines = [line.strip() for line in text.splitlines() if line.strip()]
    if lines:
        result["merchant_name"] = lines[0]

    return result

image = Image.open("receipt.jpg")
text = pytesseract.image_to_string(image)
data = parse_receipt_text(text)

print(json.dumps(data, indent=2))

Better approach for production

For real receipts, consider:

  • OCR provider with layout awareness
  • field-specific parsing rules
  • confidence scores
  • human review for low-confidence results
  • validation against known receipt patterns

If you want, I can also provide:

  • a Node.js version
  • a FastAPI endpoint
  • an example using AWS Textract / Google Vision
  • or a JSON schema for receipt data

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.