docx-create
Generate DOCX files from structured JSON data with support for text formatting, tables, images, and code blocks. Use the provided schema to define document content and layout.
Instructions
Create a new docx from JSON, returns an id. Use docx-getSchema first to understand the required JSON structure. Supports images via 'data' (base64), 'path' (local file), or 'url' (remote image with fallback).
Input Schema
Name | Required | Description | Default |
---|---|---|---|
json | Yes |
Input Schema (JSON Schema)
{
"properties": {
"json": {
"$defs": {
"Block": {
"oneOf": [
{
"$ref": "#/$defs/Paragraph"
},
{
"$ref": "#/$defs/Table"
},
{
"$ref": "#/$defs/Image"
},
{
"$ref": "#/$defs/Heading"
},
{
"$ref": "#/$defs/CodeBlock"
},
{
"$ref": "#/$defs/List"
},
{
"$ref": "#/$defs/PageBreak"
}
],
"type": "object"
},
"CodeBlock": {
"additionalProperties": false,
"properties": {
"caption": {
"type": "string"
},
"code": {
"type": "string"
},
"fontFamily": {
"default": "Consolas",
"type": "string"
},
"fontSize": {
"default": 10,
"type": "number"
},
"language": {
"type": "string"
},
"showLineNumbers": {
"default": false,
"type": "boolean"
},
"theme": {
"default": "default",
"enum": [
"default",
"dark",
"light",
"github"
]
},
"title": {
"type": "string"
},
"type": {
"const": "codeBlock"
}
},
"required": [
"type",
"code"
],
"type": "object"
},
"Heading": {
"additionalProperties": false,
"properties": {
"alignment": {
"enum": [
"left",
"center",
"right",
"justify"
]
},
"children": {
"$ref": "#/$defs/Inlines"
},
"level": {
"maximum": 6,
"minimum": 1,
"type": "integer"
},
"spacingAfter": {
"type": "number"
},
"spacingBefore": {
"type": "number"
},
"type": {
"const": "heading"
}
},
"required": [
"type",
"level",
"children"
],
"type": "object"
},
"Hyperlink": {
"additionalProperties": false,
"properties": {
"children": {
"$ref": "#/$defs/Inlines"
},
"type": {
"const": "hyperlink"
},
"url": {
"format": "uri",
"type": "string"
}
},
"required": [
"type",
"url",
"children"
],
"type": "object"
},
"Image": {
"additionalProperties": false,
"oneOf": [
{
"required": [
"data",
"format"
]
},
{
"required": [
"path"
]
},
{
"required": [
"url"
]
}
],
"properties": {
"data": {
"description": "base64-encoded image data",
"type": "string"
},
"format": {
"enum": [
"png",
"jpeg",
"jpg"
]
},
"height": {
"type": "number"
},
"path": {
"description": "local file path to image",
"type": "string"
},
"type": {
"const": "image"
},
"url": {
"description": "URL to download image from",
"type": "string"
},
"width": {
"type": "number"
}
},
"required": [
"type"
],
"type": "object"
},
"Inline": {
"oneOf": [
{
"$ref": "#/$defs/TextRun"
},
{
"$ref": "#/$defs/Hyperlink"
}
],
"type": "object"
},
"Inlines": {
"items": {
"$ref": "#/$defs/Inline"
},
"type": "array"
},
"List": {
"additionalProperties": false,
"properties": {
"bulletStyle": {
"default": "bullet",
"enum": [
"bullet",
"circle",
"square",
"dash",
"arrow"
]
},
"items": {
"items": {
"$ref": "#/$defs/ListItem"
},
"type": "array"
},
"level": {
"default": 0,
"minimum": 0,
"type": "integer"
},
"numberFormat": {
"default": "decimal",
"enum": [
"decimal",
"upperRoman",
"lowerRoman",
"upperLetter",
"lowerLetter"
]
},
"ordered": {
"default": false,
"type": "boolean"
},
"startNumber": {
"default": 1,
"minimum": 1,
"type": "integer"
},
"type": {
"const": "list"
}
},
"required": [
"type",
"items"
],
"type": "object"
},
"ListItem": {
"additionalProperties": false,
"properties": {
"children": {
"$ref": "#/$defs/Inlines"
},
"level": {
"default": 0,
"minimum": 0,
"type": "integer"
},
"subList": {
"$ref": "#/$defs/List"
}
},
"required": [
"children"
],
"type": "object"
},
"PageBreak": {
"additionalProperties": false,
"properties": {
"breakType": {
"default": "page",
"enum": [
"page",
"section",
"column"
]
},
"type": {
"const": "pageBreak"
}
},
"required": [
"type"
],
"type": "object"
},
"Paragraph": {
"additionalProperties": false,
"properties": {
"alignment": {
"enum": [
"left",
"center",
"right",
"justify"
]
},
"children": {
"$ref": "#/$defs/Inlines"
},
"indent": {
"additionalProperties": false,
"properties": {
"firstLine": {
"type": "number"
},
"left": {
"type": "number"
},
"right": {
"type": "number"
}
},
"type": "object"
},
"spacingAfter": {
"type": "number"
},
"spacingBefore": {
"type": "number"
},
"type": {
"const": "paragraph"
}
},
"required": [
"type",
"children"
],
"type": "object"
},
"Table": {
"additionalProperties": false,
"properties": {
"borders": {
"type": "boolean"
},
"rows": {
"items": {
"$ref": "#/$defs/TableRow"
},
"type": "array"
},
"type": {
"const": "table"
},
"width": {
"type": "number"
}
},
"required": [
"type",
"rows"
],
"type": "object"
},
"TableCell": {
"additionalProperties": false,
"properties": {
"children": {
"items": {
"$ref": "#/$defs/Paragraph"
},
"type": "array"
},
"colSpan": {
"minimum": 1,
"type": "integer"
},
"rowSpan": {
"minimum": 1,
"type": "integer"
}
},
"required": [
"children"
],
"type": "object"
},
"TableRow": {
"additionalProperties": false,
"properties": {
"cells": {
"items": {
"$ref": "#/$defs/TableCell"
},
"type": "array"
}
},
"required": [
"cells"
],
"type": "object"
},
"TextRun": {
"additionalProperties": false,
"properties": {
"allCaps": {
"type": "boolean"
},
"bold": {
"type": "boolean"
},
"color": {
"type": "string"
},
"fontFamily": {
"type": "string"
},
"highlight": {
"type": "string"
},
"italics": {
"type": "boolean"
},
"size": {
"type": "number"
},
"smallCaps": {
"type": "boolean"
},
"spacing": {
"type": "number"
},
"strike": {
"type": "boolean"
},
"subScript": {
"type": "boolean"
},
"superScript": {
"type": "boolean"
},
"text": {
"type": "string"
},
"type": {
"const": "text"
},
"underline": {
"type": "boolean"
}
},
"required": [
"type",
"text"
],
"type": "object"
}
},
"$id": "https://example.com/schemas/docx-schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false,
"properties": {
"content": {
"items": {
"$ref": "#/$defs/Block"
},
"type": "array"
},
"meta": {
"additionalProperties": false,
"properties": {
"category": {
"type": "string"
},
"company": {
"type": "string"
},
"createdAt": {
"format": "date-time",
"type": "string"
},
"creator": {
"type": "string"
},
"description": {
"type": "string"
},
"keywords": {
"type": "string"
},
"lastModifiedBy": {
"type": "string"
},
"manager": {
"type": "string"
},
"modifiedAt": {
"format": "date-time",
"type": "string"
},
"revision": {
"type": "string"
},
"subject": {
"type": "string"
},
"title": {
"type": "string"
}
},
"type": "object"
},
"styles": {
"additionalProperties": false,
"properties": {
"defaultFont": {
"type": "string"
},
"defaultFontSize": {
"type": "number"
}
},
"type": "object"
}
},
"required": [
"content"
],
"title": "DocxDocument",
"type": "object"
}
},
"required": [
"json"
],
"type": "object"
}