Why PDF-to-JSON is suddenly everywhere
A PDF is a layout format, not a data format — it knows where ink goes on a page, not that "Total: $4,200" is an invoice total. For decades, pulling structured fields out of documents meant brittle regex over OCR text or expensive template-based tools. Vision-capable LLMs changed the economics: a model like GPT-4o or Gemini can *read* a page the way a person does and emit clean JSON. By 2026 "PDF to JSON" is one of the most common AI features shipped in real products — invoice capture, contract review, resume parsing, lab reports.
Two approaches: schema-driven vs. document parsing
There are two distinct jobs, and confusing them is the most common mistake:
- Schema-driven extraction — you define the fields you want, the model fills them. Best when you know the target shape (an invoice always has a total, a due date, line items). Output is a predictable object.
- Document parsing — the model reconstructs the whole page into structured JSON or Markdown (headings, tables, paragraphs), preserving layout. Best when the document is unstructured or you don't know the fields in advance.
Most business workflows want the first. You supply a JSON Schema; the model returns exactly those fields:
{
"invoiceNumber": "INV-2026-0417",
"issueDate": "2026-06-30",
"dueDate": "2026-07-30",
"vendor": { "name": "Acme Supplies", "taxId": "GB123456789" },
"lineItems": [
{ "description": "Aluminium sheet 2mm", "qty": 40, "unitPrice": 12.5, "amount": 500.0 }
],
"subtotal": 500.0,
"tax": 100.0,
"total": 600.0,
"currency": "GBP"
}Vision models vs. OCR pipelines
Two families of tools, with a real trade-off:
- Vision LLMs (GPT-4o, Gemini, and open models like NuExtract 3) read the rendered page directly, so they handle messy layouts, rotated scans, and tables that OCR mangles. You pass the page image plus your schema and get JSON. Downside: cost per page and occasional hallucinated values.
- OCR + parsing services (Amazon Textract, Google Document AI, ABBYY) return structured JSON with bounding boxes and confidence scores — great when you need to know *where* on the page a value came from, for audit or human review.
A common production pattern combines them: OCR/Document AI for reliable text + coordinates, then an LLM to map that text onto your target schema.
The rule that keeps you out of trouble: validate everything
The model's JSON *looks* authoritative, which is exactly the danger — a hallucinated total is worse than a missing one. Never write extracted data straight to a database. Validate first:
- Enforce a JSON Schema on every extraction so a missing
totalor a string where you expect a number is rejected before it propagates. - Add arithmetic checks the schema can't express — do
lineItemssum tosubtotal? Doessubtotal + tax == total? Cross-field math catches a huge share of extraction errors. - When a document extracts oddly, format the raw output and diff it against a known-good example from the same template to spot the drifted field.
- Route low-confidence extractions to human review rather than trusting them silently.
To generate typed models for the extracted shape, run your schema through JSON to Python, TypeScript, or Go. For getting reliable JSON out of the model in the first place, see Get JSON From LLMs and Fix Broken JSON From LLMs.