Skip to main content

Document Definition

The document definition is the core of DocPayload. It's a JSON object that declaratively describes your entire document — layout, styles, content, headers, footers, and more. The same definition renders to PDF or DOCX.

Root structure​

{
"document": {
"metadata": { ... },
"pageSetup": { ... },
"styles": { ... },
"fonts": { ... },
"images": { ... },
"header": { ... },
"footer": { ... },
"watermarks": [ ... ],
"content": [ ... ],
"use": [ ... ],
"encryption": { ... },
"signature": { ... },
"attachments": [ ... ],
"outlines": { ... },
"diagnostics": { ... }
}
}

Only content is required. The other keys are optional — omit any you don't need.

Root keys​

The API accepts two root keys:

Root keyPurpose
"document"Full document definition. The primary and recommended root key.
"component"A reusable piece of a document (styles + content, no page setup required). Used for composition.

"documentDefinition" is a retired spelling of "document". Until 1 April 2027 the API translates it, and announces the end in the response's Deprecation and Sunset headers; after that date it is refused with the code RETIRED.

An optional "$schema" key can be added alongside the root key to enable IDE validation — it is ignored by the engine. See Editor setup below.

Editor setup​

The JSON Schema is published at:

https://schemas.docpayload.com/v1/document-definition.schema.json

Pointing your editor at it gives you autocomplete on every property, value-set hints on enum-bound fields (e.g. textAlign, fontWeight, page size), and red squiggles on typos and unknown discriminators — before you render.

Option 1 — $schema keyword (per file)​

Add a $schema key at the top of the document. Any JSON-Schema-aware editor picks it up automatically:

{
"$schema": "https://schemas.docpayload.com/v1/document-definition.schema.json",
"document": {
"content": [
{ "p": "Hello." }
]
}
}

The engine ignores $schema at render time, so it's safe to leave in production files.

Option 2 — VS Code workspace setting​

Associate every JSON file under a folder (or matching a glob) with the schema once, in .vscode/settings.json:

{
"json.schemas": [
{
"fileMatch": ["templates/**/*.json", "documents/**/*.json"],
"url": "https://schemas.docpayload.com/v1/document-definition.schema.json"
}
]
}

Adjust the fileMatch globs to wherever you keep your DocPayload sources. No need to add $schema to each file with this approach.

Option 3 — JetBrains IDEs (IntelliJ, WebStorm, Rider, …)​

Settings → Languages & Frameworks → Schemas and DTDs → JSON Schema Mappings → +. Set Schema URL to the URL above, then add a file path pattern matching where your DocPayload JSON lives.

Option 4 — Cursor and other JSON-Schema-aware editors​

The $schema keyword (Option 1) is the universal path — any editor that honors JSON Schema 2020-12 will resolve it.

What enforcement actually does​

MistakeCaught?
Unknown style property (fontWieght instead of fontWeight)Red squiggle on the key
Unknown content discriminator ({ "SVG": { … } } instead of { "svg": { … } })Red squiggle on the key
Wrong value type (fontSize: "big")Type error
Out-of-list enum (textAlign: "diagonal")Enum error with the allowed list
Bad border shorthand (borderTop: { width: 1 } instead of "1pt solid #000")Type error
Page size not in the catalog (size: "QUARTO")Enum error suggesting LETTER, A4, etc.

Keys and values are case-sensitive: FontWeight or "CENTER" squiggles in the editor and is refused by the API before rendering. Author with IntelliSense and you get the schema's spelling for free.

Properties​

PropertyTypeRequiredDescription
metadataobjectNoTitle, author, subject, keywords
pageSetupobjectNoPage size, orientation, margins, page borders
stylesobjectNoNamed reusable style definitions
fontsobjectNoCustom font-family definitions loaded from font files
imagesobjectNoKeyed image dictionary referenced by name from [image, key] Shortcodes or { "image": "key" } body nodes
headerobjectNoRepeating page header
footerobjectNoRepeating page footer with page numbering
watermarksarrayNoPage-chrome overlays applied across every page (text, image, or shape content; one entry per layer)
contentarrayYesArray of content elements
usearrayNoComponent references merged into the document (used for composition)
encryptionobjectNoPassword protection and permissions
signatureobjectNoDigital signature: PAdES or plain CMS in a PDF, an XAdES package signature in a DOCX
attachmentsarrayNoEmbed file attachments in the PDF
outlinesobjectNoDocument outline / bookmark tree. PDF only; refused under a ua-2 or WTPDF claim
diagnosticsobjectNoDraws the render's own report (warnings, notices, withheld claims) into the document, as an appendix, inline markers or both

Content elements​

The content array accepts the following element types. Each item is an object carrying exactly one of these discriminator keys (plus optional siblings like style, colspan, rowspan).

ElementKeyDescription
ParagraphpText with inline formatting
Headingh1–h6Semantic headings with built-in sizing
TitletitleThe document's title as drawn on the page: tagged as a title, never a heading, so it stays out of the outline and the TOC
TabletableRows and columns with cell styling, colspan / rowspan
Ordered ListolNumbered list
Unordered ListulBulleted list
ColumnscolumnsMulti-column layout
Horizontal RulehrHorizontal rule with line styles, alignment, fill, and spacing
ImageimageStandalone image element
BarcodeShortcodes / SVG64 supported symbologies via the [barcode, …] Shortcode inside text, or as a barcode element inside an SVG svg block
Form Fieldfield / ShortcodesInteractive fields: the field block takes text, textArea, checkbox, radio, choice, listBox or signature; inside text, Shortcodes add the same kinds plus a date picker
SVGsvgSVG-aligned drawing primitives (line, rect, circle, path, text, image…) as children, with an optional viewBox
Page breakbreakpage, section or line; left, right, recto or verso break until the next page is that side
Table of contentstocAuto-generated TOC from the headings, down to its depth (default 3)

Unknown discriminator keys are rejected at validation time — typos like { "SVG": { … } } won't render silently empty; the engine errors out so the typo is obvious.

Minimal example​

The simplest valid document:

{
"document": {
"content": [
{ "h1": "Hello, World!" },
{ "p": "Generated by DocPayload." }
]
}
}