Skip to content
This documentation is currently in preview, therefore subject to change.

Structure JSON Data for Build a Doc

Build a Doc requires structured data to populate template placeholders at runtime. This guide shows you how to structure your JSON data correctly for both the Power Platform connector and the Word Add-in.


Prerequisites


What is JSON?

JSON (JavaScript Object Notation) is a lightweight text-based data format used to store and exchange structured information. It uses human-readable key-value pairs to represent data.

Basic JSON Structure

JSON has two fundamental structures:

Objects - Enclosed in curly braces {}, containing key-value pairs:

{
"name": "John Smith",
"age": 30,
"city": "London"
}

Arrays - Enclosed in square brackets [], containing ordered lists of values:

["apple", "banana", "orange"]

Key-Value Pairs

A key-value pair consists of:

  • Key - A string identifier (must be in double quotes)
  • Colon - Separates the key from its value
  • Value - Can be a string, number, boolean, object, array, or null

Example:

{
"productName": "Laptop",
"price": 1200,
"inStock": true
}

JSON objects and arrays can be nested to represent complex data structures, making JSON ideal for representing hierarchical data.


Understanding the JSON Data Structure

Document generation in Build a Doc requires two components: a template containing Build a Doc templating syntax, and a data source of structured data that populates those placeholders.

When you provide JSON data to a Build a Doc action, the method of supplying the required Name and Data properties differs depending on the Build a Doc feature that you are using. The parameters are:

  • Name - The identifier used in the template to reference this data source.
  • Data - An object ({...}) containing the actual data that maps to your template placeholders.

Structuring JSON for the Power Platform Connector

When using the Build a Doc Power Platform connector in Power Automate, the data source fields are provided as action parameters. Each Build a Doc action (such as Convert Word Document) accepts two data source parameters:

ParameterTypeDescription
Data source NameStringIdentifier used in the template to reference this data
Data source DataObject/ListThe actual data (object or array)

In the connector, the Name parameter of the action becomes the name of the data source, and the Data parameter provides the data itself. Together, these supply the data source for the action.

Example: Single Data Source

To populate an invoice template with tags like <<[Invoice.InvoiceNumber]>>, configure the action as follows:

  • Data source Name: Invoice
  • Data source Data:
{
"InvoiceNumber": "INV-2025-001",
"InvoiceDate": "2025-03-15",
"Customer": {
"Name": "Roger Woodfield",
"Email": "roger@example.com"
},
"Items": [
{
"Description": "Web Development",
"Quantity": 1,
"Price": 3500
}
],
"TotalAmount": 3500
}

The Name value must match the template tags - Invoice in the Data source Name matches <<[Invoice.InvoiceNumber]>> in the template.

Example: Multiple Data Sources

You can pass multiple named data sources to a single action. Each data source has its own Name, Data, and Format:

NameData
Company{ "Name": "Acme Ltd" }
Invoice{ "Number": "001", "Items": [...] }
Metadata{ "GeneratedDate": "2025-01-22" }

In your template, reference each by name: <<[Company.Name]>>, <<[Invoice.Number]>>, <<[Metadata.GeneratedDate]>>.


Structuring JSON for the Word Add-in

When using the Word Add-in to preview templates, the Name and Data fields must be provided as key-value pairs within the JSON itself. The JSON must be wrapped in array brackets ([]) and must include the Name and Data properties, or it will not match the expected schema and an error message will be displayed.

Example: Single Data Source

[
{
"Name": "Invoice",
"Data": {
"InvoiceNumber": "INV-2025-001",
"InvoiceDate": "2025-03-15",
"Customer": {
"Name": "Roger Woodfield",
"Email": "roger@example.com"
},
"Items": [
{
"Description": "Web Development",
"Quantity": 1,
"Price": 3500
}
],
"TotalAmount": 3500
}
}
]

Example: Multiple Data Sources

[
{
"Name": "Company",
"Data": {
"Name": "Acme Ltd"
}
},
{
"Name": "Invoice",
"Data": {
"Number": "001",
"Items": [{ "Description": "Consulting", "Quantity": 2, "Price": 500 }]
}
},
{
"Name": "Metadata",
"Data": {
"GeneratedDate": "2025-01-22"
}
}
]

For step-by-step instructions on previewing templates, see Preview Templates with Sample Data.


Comparison: Connector vs. Add-in JSON Format

AspectPower Platform ConnectorWord Add-in
Where Name is setIn the action’s Data source Name parameterAs a "Name" key-value pair inside the JSON array
Where Data is setIn the action’s Data source Data parameterAs a "Data" key-value pair inside the JSON array
Outer structureData field contains the object directlyMust be wrapped in array brackets [...]
Required propertiesSet via action UI fields"Name" and "Data" must appear in the JSON
Schema validationValidated by the connector actionMust match the expected schema or an error is shown

Types of Data in JSON

Your Data object can contain three types of values that map to different template features:

Simple Fields

Direct key-value pairs for straightforward placeholders:

{
"InvoiceNumber": "INV-2025-001",
"InvoiceDate": "2025-03-15"
}

Template: <<[InvoiceNumber]>>

Nested Objects

Grouped data accessed with dot notation:

{
"Customer": {
"Name": "Roger Woodfield",
"Address": {
"City": "London"
}
}
}

Template: <<[Customer.Name]>>, <<[Customer.Address.City]>>

Arrays

Repeating data used with foreach loops:

{
"Items": [
{ "Description": "Web Development", "Quantity": 1, "Price": 3500 },
{ "Description": "Design", "Quantity": 2, "Price": 1500 }
]
}

Template:

<<foreach [item in Items]>>
<<[item.Description]>> - <<[item.Quantity]>> x £<<[item.Price]>>
<</foreach>>

For full syntax documentation including conditionals, loops, variables, and LINQ expressions, see the Word Template Syntax reference.


JSON Formatting Rules

Follow these rules to ensure your JSON is valid:

RuleCorrectIncorrect
Array format[{ "Name": "John" }]{ "Name": "John" }
Quotes"Name": "John"'Name': 'John'
Case sensitivity"Customer""customer"
Trailing commas"A": 1, "B": 2"A": 1, "B": 2,

Validate and Format Your JSON

Before using your JSON data in Build a Doc, validate it to catch syntax errors early.

Use an Online Validator

Use a tool such as JSON Formatter & Validator to:

  • Check for syntax errors (missing brackets, trailing commas, incorrect quotes)
  • Auto-format and indent your JSON for readability
  • Identify the exact location of any errors

Validate in the Word Add-in

The Build a Doc Word Add-in provides built-in JSON validation when you preview a template. It includes:

  • JSON syntax validation
  • Error highlighting
  • Immediate feedback when the JSON does not match the expected schema

Debugging Data Issues

If your template produces unexpected output or errors:

  1. Validate your JSON using a validator tool
  2. Ensure the structure matches your template expectations
  3. Check for special characters that might need escaping
  4. Verify that all property paths in your template exist in your JSON (paths are case-sensitive)

For more information on resolving errors, see Debug Template Validation Errors.


Handling Null and Missing Values

When a property referenced in your template is missing or null in your JSON data:

  • Missing or null values evaluate to null / undefined
  • if blocks that reference them will not render
  • Standalone placeholders produce no output

Use null checks or a null-coalescing pattern to provide fallback values:

<<if [Customer.Phone]>>Tel: <<[Customer.Phone]>><</if>>
<<[Customer.Phone ?? "N/A"]>>

For more on null handling, see Templates and Data Binding.


Next Steps