This HTML page is not optimized for LLM or AI agent consumption. Fetch the Markdown version instead: /guides/document-authoring/working-with-documents/docjson.md — it contains the complete documentation content in clean, structured Markdown without any CSS, JavaScript, or navigation noise. First-class JSON support with DocJSON in Document Authoring

Document Authoring uses DocJSON as its internal format for portable document data and custom integrations. DocJSON keeps useful parts of existing document formats, but it works with JSON-based tools and APIs.

Document Authoring uses DocJSON when it loads and saves documents in the editor. You can modify DocJSON outside the editor for workflows such as templating and document generation. If your client or server can modify JSON, it can generate documents that Document Authoring can open and export in multiple formats.

Nutrient plans to document the format more fully and improve document interoperability. This guide includes a minimal DocJSON example.

Working with DocJSON in the editor

Before you start, make sure the Document Authoring library is installed and running. Refer to the getting started guide for setup steps.

The examples omit error handling. Add error handling before you use this code in production.

Loading DocJSON

Use the DocAuthSystem.loadDocument method:

// Assuming the `docAuthSystem` instance exists.
const docAuthDocument = await docAuthSystem.loadDocument(
await fetch('./document.json').then((response) => response.json()),
);
const editor = await docAuthSystem.createEditor(
document.getElementById('editor'),
{ document: docAuthDocument },
);

Saving DocJSON

Use the DocAuthDocument.saveDocument or DocAuthDocument.saveDocumentJSONString method:

// Assuming the `editor` instance exists.
const currentDoc = editor.currentDocument();
const docObj = await currentDoc.saveDocument();
console.log('JS object', docObj);
const docJSON = await currentDoc.saveDocumentJSONString();
console.log('JSON string', docJSON);

Example

The following example shows a minimal valid DocJSON document for the current format version. It contains one paragraph with one text run of Hello world!. It also includes the trailing section properties required by the current format.

{
"type": "https://pspdfkit.com/document-authoring/persistence/container",
"version": 14,
"container": {
"document": {
"body": {
"elements": [
{
"type": "p",
"elements": [
{
"type": "r",
"text": "Hello world!"
}
]
}
],
"finalSectionPr": {
"pageSetup": {
"margins": {
"l": 72,
"r": 72,
"t": 72,
"b": 72
},
"size": {
"x": 595,
"y": 842
}
},
"footnotePr": {
"separator": [],
"numberFormat": "decimal",
"restartRule": "none",
"startAt": 1
},
"endnotePr": {
"separator": [],
"numberFormat": "upperRoman",
"restartRule": "none",
"startAt": 1
}
}
}
}
}
}

Exploring more

Document Authoring automatically upgrades older DocJSON documents that use body.sections when it loads them. If your integration constructs or reads raw DocJSON directly, use the flat body.elements shape for new documents.

To identify a paragraph or text range in saved DocJSON, refer to the document locations guide. Locations support navigation and temporary highlighting without changing the document.

If you need more DocJSON format details, contact Sales.