TL;DR If a PDF is tagged, its text sits inside a hierarchy of structure elements such as headings, paragraphs, lists and tables, and JPedal can write that structure out as JSON. Create an ExtractStructuredTextProperties, set its output mode to OutputModes.JSON, and pass it to ExtractStructuredText.writeAllStructuredTextOutlinesToDir(). An untagged PDF has no structure to export: you can still extract its plain text, but not as structured JSON.
Contents:
- What is a tagged PDF?
- What is JSON?
- PDF vs JSON
- Requirements
- How to extract text from a PDF as JSON
- Frequently asked questions
What is a tagged PDF?
Some PDF files are “tagged”, which means they contain information about the structure of the file. This structure is embedded as metadata within the PDF and is made up of a hierarchy of tags that label elements such as headings, paragraphs, lists, tables, and images.
This is very similar to HTML, where text is contained within elements that have meaning, such as <p> for a paragraph or <table> for a table.
If a PDF file does contain structured content (also known as marked content), then it can be processed and converted into other formats. Not sure whether yours does? See how to find out if a PDF file has structured content, or learn more about tagged PDF files.
What is JSON?
A JSON file (short for JavaScript Object Notation) is a lightweight, text-based format used for storing and exchanging structured data between systems.
It represents data as key-value pairs and arrays, making it easy for both machines and developers to read and write. JSON is commonly used in web applications to send data between a server and a client, and is natively supported by most programming languages.
Despite its origin in JavaScript, JSON is language-independent and has become a universal data format across APIs and software systems.
PDF vs JSON
The two formats serve distinct purposes. PDF preserves the fixed visual layout of a document, which makes it ideal for sharing print-ready content like reports, contracts and official documents. It is the format to use when a document must look the same on every device, and it is one of the most universally supported document formats.
JSON is designed for data exchange and storage, not presentation. It is used across web development, APIs and software applications to send structured data like user profiles, settings or real-time content between servers and clients.
JSON is plain text, so you can open and edit it in any text editor such as VS Code. A PDF is not built to be edited that way, which is why you can’t just open and edit a PDF file. Its structure also makes JSON far easier than PDF for AI tools such as LLMs to parse.
Requirements
- A JPedal jar, either the trial or a licensed build, on your class or module path
- A tagged PDF file
How to extract text from a PDF as JSON
JPedal supports extracting structured content as JSON through the ExtractStructuredText class. Set the output mode on an ExtractStructuredTextProperties object, then pass it in as the last parameter:
final ExtractStructuredTextProperties properties = new ExtractStructuredTextProperties();
properties.setFileOutputMode(OutputModes.JSON);
ExtractStructuredText.writeAllStructuredTextOutlinesToDir("inputFile.pdf", password, "outputFolder", null, properties);
The input can be a single PDF or a folder of them, and password is the PDF’s password, if it has one. The fourth parameter is an optional ErrorTracker, which you can leave as null.
To write the document’s figures out as images alongside the JSON, use writeAllStructuredTextOutlinesAndFiguresToDir() instead. It takes the same parameters, followed by a folder for the figures, the image format to write them in, and a scaling factor (1.0f is the original size):
ExtractStructuredText.writeAllStructuredTextOutlinesAndFiguresToDir("inputFile.pdf", password, "outputFolder", null, properties, "figuresFolder", imageFormat, 1.0f);
JSON is one of several output modes. The same code can write structured content as ePUB, HTML, Markdown, XML or YAML by changing the OutputModes value.
Frequently asked questions
Can all PDF files be converted to JSON?
No. Only PDFs that contain structured or tagged content can be accurately converted into structured JSON. Untagged PDFs may still allow plain text extraction, but the semantic structure of the document is often lost.
What does “tagged PDF” mean?
A tagged PDF includes metadata describing the logical structure of the document, such as headings, paragraphs, tables, lists, and images. This makes the document more accessible and easier to process programmatically.
Why convert PDF to JSON?
Converting PDF content to JSON makes it easier to integrate document data into applications, APIs, databases, search systems, and AI workflows. JSON is lightweight, structured, and widely supported across programming languages.
Can JSON preserve the visual layout of a PDF?
Not completely. JSON represents structured data rather than visual appearance. Structural relationships can be preserved, but the exact page layout and formatting of the original PDF are not the goal.
Is JSON suitable for AI and LLM processing?
Yes. The structured format makes document content easier to parse, chunk, index, and analyze programmatically, which suits AI pipelines and large language models.
We have been working with PDFs for over 25 years and have other resources to help you learn more about the PDF format.