The response to a processing request contains a Document
object that holds everything known about the processed document, including all
of the structured information that Document AI was able to extract.
This page explains the layout of the Document object by providing sample documents,
and then mapping aspects of OCR results to the specific elements of the Document object JSON.
It also provides client libraries
code samples and Document AI Toolbox SDK code samples.
These code samples use online processing, but the Document object parsing works
the same for batch processing.

The orange and blue rectangles and arrows represent that at least one field of
the connected objects is .layout or detectedLanguage, respectively. The
diagram uses crow's foot
notation.
Use a JSON viewer or editing utility specifically designed to expand or collapse elements. Reviewing raw JSON in a plain text utility is inefficient.
Text, layout, and quality scores
Here's a sample text document:

Here's the full document object as returned by the Enterprise Document OCR processor:
This OCR output is also always included in Document AI processor output, since OCR is run by the processors. It uses the existing OCR data, which is why you can enter such JSON data using the inline document option into Document AI processors.
image=None, # all our samples pass this var
mime_type="application/json",
inline_document=document_response # pass OCR output to CDE input - undocumented
Here are some of the important fields:
Raw text
The text field contains the text that is recognized by Document AI.
This text doesn't contain any layout structure other than spaces, tabs, and
line feeds. This is the only field that stores a document's textual
information and serves as the source of truth of the document's text. Other
fields can refer to parts of the text field by position (startIndex and endIndex).
{
text: "Sample Document\nHeading 1\nLorem ipsum dolor sit amet, ..."
}
Page size and languages
Each page in the document object corresponds to a
physical page from the sample document. The sample JSON output contains one
page because is a single PNG image.
{
"pages:" [
{
"pageNumber": 1,
"dimension": {
"width": 679.0,
"height": 460.0,
"unit": "pixels"
},
}
]
}
- The
pages[].detectedLanguages[]field contains the languages found on a given page, along with the confidence score.
{
"pages": [
{
"detectedLanguages": [
{
"confidence": 0.98009938,
"languageCode": "en"
},
{
"confidence": 0.01990064,
"languageCode": "und"
}
]
}
]
}
OCR data
Document AI OCR detects text with various granularity or organization in the page, such as the text blocks, paragraphs, tokens and symbols (symbol level is optional, if configured to output symbol level data). These are all members of the page object.
Every element has a corresponding layout that
describes its position and text. Non-text visual elements
(such as checkboxes) are also at the page level.
{
"pages": [
{
"paragraphs": [
{
"layout": {
"textAnchor": {
"textSegments": [
{
"endIndex": "16"
}
]
},
"confidence": 0.9939527,
"boundingPoly": {
"vertices": [ ... ],
"normalizedVertices": [ ... ]
},
"orientation": "PAGE_UP"
}
}
]
}
]
}
The raw text is referred to in the textAnchor
object which is indexed into the main text string with startIndex and endIndex.
For
boundingPoly, the top-left corner of the page is the origin(0,0). Positive X values are to the right, and positive Y values are down.The
verticesobject uses the same coordinates as the original image, whereasnormalizedVerticesare in the range[0,1]. There is a transformation matrix that indicates the measures deskewing and other attributes of the normalization of the image.
- To draw the
boundingPoly, draw line segments from one vertex to the next. Then, close the polygon by drawing a line segment from the last vertex back to the first. The orientation element of the layout indicates whether the text has been rotated relative to the page.
To help you visualize the document's structure, the following images draw bounding
polygons for page.paragraphs,
page.lines, page.tokens.
Paragraphs

Lines

Tokens

Blocks

The Enterprise Document OCR processor can perform quality assessment of a document based on its readability.
- You must set the field
processOptions.ocrConfig.enableImageQualityScorestotrueto get this data in the API response.
This quality assessment is a quality score in [0, 1], where 1 means perfect quality.
The quality score is returned in the Page.imageQualityScores field.
All detected defects are listed as quality/defect_* and sorted in descending
order by confidence value.
Here's a PDF that is too dark and blurry to comfortably read:
Here's the document quality information as returned by the Enterprise Document OCR processor:
{
"pages": [
{
"imageQualityScores": {
"qualityScore": 0.7811847,
"detectedDefects": [
{
"type": "quality/defect_document_cutoff",
"confidence": 1.0
},
{
"type": "quality/defect_glare",
"confidence": 0.97849524
},
{
"type": "quality/defect_text_cutoff",
"confidence": 0.5
}
]
}
}
]
}
Code samples
The following code samples demonstrate how to send a processing request and then read and print the fields to the terminal:
Java
For more information, see the Document AI Java API reference documentation.
To authenticate to Document AI, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.