Docling OCRIndependent Docling guide

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, or docling convert file.pdf --to json writes 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_ref and 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:

ExportMethod / flagWhat it keepsBest for
Markdownexport_to_markdown() / --to mdReading order, headings, table textHumans, note apps, plain-text RAG
JSONexport_to_dict() / --to jsonStructured items, tables, some geometryPipelines, databases, APIs
DocTags--to doctagsLossless — every layout artefact incl. cell spansRound-trips, exact reconstruction
Fidelity goes up as you move down the table; the cost is file size and complexity.

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.

Python — parse and export 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 model

From 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.

CLI — JSON and DocTags
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 once

What 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_ref and 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.

Python — iterate items and find tables
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 browser

Keep reading