Overview
ToJson() returns document content as structured data rather than a Markdown string. Every text block, image, and table on each page is represented as a JSON object with positional metadata attached.
This makes it the right choice when you need to:
- Build a custom rendering or post-processing pipeline
- Access bounding box coordinates for text and image regions
- Detect headings, bold text, or other styled elements programmatically
- Pass structured layout data to a downstream model or search index
Output structure
The return value is a JSON array — one object per processed page. See the JSON schema guide for a full field reference.Working with bounding boxes
Every block carries abbox field — a four-element array [x0, y0, x1, y1] describing the rectangle that bounds that element.
Extracting span-level data
Spans are the most granular unit in the JSON output. Each span represents a run of text sharing the same font, size, and style flags. This lets you identify headings, bold text, and other styled elements programmatically:Font flags reference
Theflags field is a bitmask encoding font properties:
Example interpretation
Consider the following span JSON:flags = 6
flags = 6 on "Italic text." with font MinionPro-It
6 = 2 + 4
Consistent with italic + serifed text.
flags = 0
flags = 0 on "Hello World!" with font Arial
0 is consistent with regular (unstyled) text.
flags = 20
flags = 20 on "This is bold" with font MinionPro-Bold
20 = 16 + 4
Consistent with bold + serifed text.
So the extracted styling in plain English is:
"Italic text." → italic
"Hello World!" → regular
"This is bold" → bold
Page selection
As withToMarkdown(), you can limit extraction to specific pages:
Saving JSON output
Write the result to a.json file:
Full example — building a custom text pipeline
For the full API signature, see the ToJson() API reference.
Next steps
JSON Schema
Full field descriptions for every object in the JSON output.
Extract Markdown
Preserve structure and formatting for LLM pipelines.
Extract Text
Get clean, plain text output.