Output · JSON
Getting JSON out of Docling (and why it beats the Markdown export)
Docling's Markdown output is convenient and lossy. The JSON output is the opposite: it keeps the full document model — page geometry, table cells, spans, reading order — so you can hand it to a database, a RAG pipeline, or any code that needs structure, not prose.
Updated 2026-10-26 · 3 min read
The short version
- –One call:
result.document.export_to_dict()returns the whole parsed document as a JSON-serialisable dict, ordocling convert file.pdf --to jsonwrites it to a file. - –Markdown drops cell spans, page numbers and exact geometry. JSON and DocTags keep them, which is why "PDF to structured data" work should read JSON, not the Markdown export.
- –DocTags (
--to doctags) is the lossless format — it preserves every layout artefact, including table cell boundaries, and is round-trippable back to a document. - –The document model is a list of items (text, table, heading, picture…) in reading order, each with a
self_refand geometry, so you can walk it in code.
The three export levels
Docling gives you the same parsed document at three levels of fidelity. Pick by what the downstream system can consume:
| Export | Method / flag | What it keeps | Best for |
|---|---|---|---|
| Markdown | export_to_markdown() / --to md | Reading order, headings, table text | Humans, note apps, plain-text RAG |
| JSON | export_to_dict() / --to json | Structured items, tables, some geometry | Pipelines, databases, APIs |
| DocTags | --to doctags | Lossless — every layout artefact incl. cell spans | Round-trips, exact reconstruction |
The one-liner
The Python path is the same converter you already use; the export call is what changes. export_to_dict() returns a plain Python structure that serialises straight to JSON.
from docling.document_converter import DocumentConverter
import json
result = DocumentConverter().convert("statement.pdf")
doc_dict = result.document.export_to_dict()
print(json.dumps(doc_dict, indent=2)[:500]) # the whole document modelFrom the command line
The CLI writes the same outputs to a file next to the input. --to json is what you want for a data pipeline; --to doctags when you need the lossless form.
docling convert statement.pdf --to json # statement.json
docling convert statement.pdf --to doctags # lossless DocTags
docling convert statement.pdf --to md --to json # both at onceWhat JSON keeps that Markdown throws away
The Markdown export is designed to read well in a note app. It flattens the document: a table becomes a Markdown pipe-table, a merged cell becomes an empty slot, and the fact that "Net sales" was a row header is gone.
The JSON model keeps the items as objects in reading order. A table is a table item whose cells carry geometry and provenance; a heading knows its level; a picture keeps its caption. For any workflow where you need to know which cell this number came from, JSON is the only output that has the answer.
- Tables stay structured — cells, spans and geometry, not a flattened pipe-table.
- Reading order is explicit, so you do not re-derive it from coordinates.
- Every item has a
self_refand provenance, so a number can be traced back to its page and position.
Walking the document model in code
The JSON structure is a list of top-level page items in reading order. The exact schema evolves between releases, so the robust way to consume it is to walk the parsed DoclingDocument in Python — that API is stable even when the dict layout changes.
from docling.document_converter import DocumentConverter
result = DocumentConverter().convert("statement.pdf")
doc = result.document
for item, _level in doc.iterate_items():
if item.label.value == "table":
df = item.export_to_dataframe() # pandas DataFrame of the cells
print(df.head())If you only want tables as clean data, the shorter path is the Excel route in the Docling to Excel guide — it turns the same table items into a spreadsheet you can sum.
When to use JSON instead of Markdown
- Feeding a database or API → JSON is already structured.
- RAG with metadata → JSON lets you attach table provenance to chunks, not just text.
- Table extraction → JSON preserves cells; Markdown does not.
- Reading in a note app → use Markdown, it is what it is for.
- Exact round-trip → DocTags is the lossless choice.
Frequently asked questions
How do I convert a PDF to JSON with Docling?+
docling convert file.pdf --to json from the CLI, or result.document.export_to_dict() in Python. Both return the full parsed document model, not just the text.
What is the difference between Docling JSON and Markdown?+
Markdown flattens the document for readability and drops cell spans and geometry. JSON keeps the structured items — tables with cells, headings with levels, reading order — so it is the right choice for data pipelines.
Is DocTags the same as JSON?+
No. JSON is a structured-but-simplified view; DocTags is lossless and preserves every layout artefact including exact table cell boundaries, so it can be reconstructed back into a document.
Can I get only the tables as JSON?+
Yes — iterate the document items and filter for label == "table", or use the Excel export for a spreadsheet directly. See the Docling to Excel guide.
Does export_to_dict change between versions?+
The dict schema can shift between releases. If you parse the raw dict, pin your version; if you walk the DoclingDocument API in Python, you are insulated from most changes.
Try it online
Run the same pipeline in the browser — no install, no uploads stored.
Try it in the browserKeep reading
- PDF to Markdown
The lossy, human-friendly sibling
- Docling to Excel
Tables into a spreadsheet
- Chunking for RAG
From JSON structure to chunks
- Python API quickstart
The converter in ten lines
- CLI reference
Every --to flag