---
title: "Extracting structured JSON data from PDF documents | Nutrient Python SDK"
canonical_url: "https://www.nutrient.io/guides/python/extraction/json-data-extraction/"
md_url: "https://www.nutrient.io/guides/python/extraction/json-data-extraction.md"
last_updated: "2026-04-14T00:00:00.000Z"
description: "Extract structured JSON data from PDF documents using OCR with Nutrient Python SDK."
---

# Extracting structured JSON data from PDF documents

Extract structured data from PDF files as JSON for storage, API workflows, or analytics pipelines. This approach reduces manual entry and gives your application direct access to document content.

[Download sample](https://www.nutrient.io/downloads/samples/python/json-data-extraction.zip)

## How Nutrient supports this workflow

Nutrient Python SDK handles structured extraction from PDF documents, including digital-native PDFs and PDFs that mix digital text with scanned content.

In this sample, `VisionEngine.ADAPTIVE_OCR` uses an adaptive extraction pipeline that prefers native PDF text when available and falls back to OCR for image-based content when needed.

You don’t need to manage:

- Third-party OCR engine integration

- Switching between native-text extraction and OCR

- Document layout parsing

- Model download and initialization

- Conversion from extracted output to structured data

Use the SDK API to extract structured JSON in your application.

## Complete implementation

This example shows a complete PDF-to-JSON extraction flow.

Import the required Nutrient classes:

```python

from nutrient_sdk import Document
from nutrient_sdk import Vision
from nutrient_sdk import NutrientException
from nutrient_sdk import VisionEngine

```

Open the PDF with a Python [context manager](https://docs.python.org/3/reference/datamodel.html#context-managers). The context manager closes the document automatically:

```python

def main():
    try:
        with Document.open("input.pdf") as document:

```

Configure the Adaptive OCR engine, extract JSON content, and write it to `output.json`. Catch `NutrientException` to handle SDK errors:

```python

            document.settings.vision_settings.engine = VisionEngine.ADAPTIVE_OCR

            vision = Vision.set(document)
            content_json = vision.extract_content()

            with open("output.json", "w", encoding="utf-8") as f:
                f.write(content_json)

            print("Successfully extracted content to output.json")
    except NutrientException as e:
        print(f"Error: {e}")

if __name__ == "__main__":
    main()

```

## Understanding JSON output

`extract_content()` returns the public layout JSON structure for Vision extraction. The JSON document has an `elements` array. Each element represents one detected layout item in reading order.

The top-level JSON object contains these fields:

| Field               | Description                                                                                                                            |
| ------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| `metadata`          | Optional per-page metadata array (one entry per page), including page size, resolution, skew angle, and rotation angle when available. |
| `elements`          | Layout elements sorted by reading order.                                                                                               |
| `classification`    | Optional document classification result when classification was run.                                                                   |
| `languageDetection` | Optional document language detection result when language detection was run.                                                           |

Each entry in `elements` includes common fields such as `type`, `id`, `bounds`, `confidence`, `readingOrder`, and `pageNumber`. The `bounds` object contains `x`, `y`, `width`, and `height` values in page-image coordinates. `pageNumber` is 1-based.

Common element types include:

| `type` Value     | Additional Fields                                                                                                                                            |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `paragraph`      | `role`, `text`, and optional `words`.                                                                                                                        |
| `handwriting`    | `text` and optional `words`.                                                                                                                                 |
| `table`          | `rowCount`, `columnCount`, and `cells`. Each cell includes 0-based `row` and `column` indexes, `rowSpan`, `colSpan`, `text`, `bounds`, and optional `words`. |
| `keyValueRegion` | `pairs`, where each pair contains a key entity, value entity, and relationship confidence.                                                                   |
| `barcode`        | `value` and `format`.                                                                                                                                        |
| `picture`        | `classification`, `classificationConfidence`, `altDescription`, and optional caption or footnote references.                                                 |
| `chart`          | `htmlTable`, optional `summary`, optional `classification`/`classificationConfidence`, and optional caption or footnote references.                          |
| `formula`        | `latex`.                                                                                                                                                     |
| `form`           | `fields`, where each field includes bounds, confidence, field type, and optional label data.                                                                 |

A minimal output can look like this:

```json

{
  "elements": [
    {
      "type": "paragraph",
      "id": "paragraph-1",
      "bounds": {
        "x": 72,
        "y": 96,
        "width": 468,
        "height": 24
      },
      "confidence": 0.99,
      "readingOrder": 0,
      "pageNumber": 1,
      "role": "Text",
      "text": "Invoice number INV-1001"
    }
  ]
}

```

Word-level data appears in `words` arrays when word output is enabled and available for the selected extraction engine.

## Barcode data in JSON output

For documents that contain machine-readable codes, Vision extraction includes detected barcode data in the document layout output. Each detected barcode is represented as a layout element with the decoded value and barcode symbology, such as 1D barcodes, QR codes, Micro QR codes, PDF417, DataMatrix, Aztec, or MaxiCode.

Use this output when a pipeline needs both document text and embedded barcode values from the same pass. To focus specifically on barcodes, refer to the [read barcodes with Vision](https://www.nutrient.io/guides/python/extraction/read-barcodes-with-vision.md) guide.

## Summary

The extraction flow has four steps:

1. Open the PDF document.

2. Configure the Adaptive OCR engine.

3. Extract content as JSON with `Vision`.

4. Write the JSON output to a file.

Nutrient handles adaptive extraction and content structuring, so you don’t need to implement PDF parsing, native-text detection, or OCR fallback logic.

You can download [this sample package](https://www.nutrient.io/downloads/samples/python/json-data-extraction.zip) to run the example locally.
---

## Related pages

- [Nutrient Python SDK extraction guides](/guides/python/extraction.md)
- [Applying OCR to a PDF page](/guides/python/extraction/apply-ocr-to-pdf-page.md)
- [Applying OCR to a PDF document](/guides/python/extraction/apply-ocr-to-pdf.md)
- [Classifying documents](/guides/python/extraction/classify-document.md)
- [Generating image descriptions using Claude](/guides/python/extraction/describe-image-with-claude.md)
- [Generating image descriptions using local AI](/guides/python/extraction/describe-image-with-local-ai.md)
- [Generating image descriptions using OpenAI](/guides/python/extraction/describe-image-with-openai.md)
- [Detecting document language](/guides/python/extraction/detect-document-language.md)
- [Extracting data from images using ICR](/guides/python/extraction/extract-data-from-image-icr.md)
- [Extracting data from images using OCR](/guides/python/extraction/extract-data-from-image-ocr.md)
- [Extracting data from images using vision language models](/guides/python/extraction/extract-data-from-image-vlm.md)
- [Extracting data from specific PDF pages](/guides/python/extraction/extract-data-from-specific-pages.md)
- [Extracting form fields from images](/guides/python/extraction/extract-form-fields-from-image.md)
- [Extracting structured data from documents](/guides/python/extraction/extract-structured-data.md)
- [Generating extraction schemas](/guides/python/extraction/generate-extraction-schema.md)
- [Labeling form fields with a vision language model](/guides/python/extraction/label-form-fields-with-vlm.md)
- [Opening password-protected PDFs](/guides/python/extraction/open-password-protected-pdf.md)
- [Extracting text from PDF documents](/guides/python/extraction/pdf-to-text.md)
- [Reading barcodes with vision extraction](/guides/python/extraction/read-barcodes-with-vision.md)
- [Extracting text from multilingual images](/guides/python/extraction/read-text-from-image-multi-language.md)
- [Extracting text from images](/guides/python/extraction/read-text-from-image.md)
- [Later, in another process — no document needed:](/guides/python/extraction/search-document-text.md)
- [Speeding up first ICR operation by predownloading models](/guides/python/extraction/speed-up-first-icr-by-downloading-requirements.md)
- [Split documents](/guides/python/extraction/split-document.md)

