Products Technologies Demo Docs Blog Support Company

ReportingCloud: The MergeData JSON Object Format Explained

ReportingCloud merge operations accept a JSON object containing data for all merge fields and blocks. The .NET wrapper serializes typed business objects to JSON automatically via MergeBody and MergeData properties, supporting nested merge blocks and multiple top-level records.

ReportingCloud: The MergeData JSON Object Format Explained

When merging templates with data, a JSON object contains merge data for all merge fields and merge blocks in the document. Using the language specific wrappers, the JSON object is created automatically and you don't need to know the exact expected JSON structure. For example, the .NET wrapper accepts an object as data which is then transformed to the required JSON data implicitly.

Consider the following .NET class:

public class Invoice
{
    public string name { get; set; }
    public string invoice_no { get; set; }
}

Now, an instance of that object is created and passed to the MergeData property of the MergeBody object:

// create dummy data
Invoice invoice = new Invoice();
invoice.name = "Text Control, LLC";
invoice.invoice_no = "Test_R667663";

// create a new MergeBody object
MergeBody body = new MergeBody();
body.MergeData = invoice;

In the MergeDocument method, the MergeBody object is simply passed as a parameter:

// merge the document
List<byte[]> results = rc.MergeDocument(body, templateName, ReturnFormat.PDF);

Internally, the wrapper is creating the expected JSON format of the complete MergeBody object:

{
  "mergeData": {
    "name": "Text Control, LLC",
    "invoice_no": "Test_R667663"
  },
  "template": null,
  "mergeSettings": null
}

The sample template, that gets copied into your template storage when creating a trial account, contains top level merge fields and a merge block that contains separate merge fields:

ReportingCloud: The mergeData JSON object format explained

Top level merge fields are all fields in a template that are not part of a merge block. The complete template is repeated based on the number of records (array entries) in the merge data. Merge fields encapsulated in a merge block are repeated based on the number of merge block data rows in the JSON array. Additionally, merge blocks can be nested in unlimited levels. The following JSON data contains 1 top level record:

[
        {
          "yourcompany_companyname": "Text Control, LLC",
          "yourcompany_zip": "28226",
          "item": [
                {
                  "qty": "1",
                  "item_no": "1",
                  "item_description": "Item description 1",
                  "item_unitprice": "2663",
                  "item_discount": "20",
                  "item_total": "2130.40"
                },
                {
                  "qty": "1",
                  "item_no": "2",
                  "item_description": "Item description 2",
                  "item_unitprice": "5543",
                  "item_discount": "0",
                  "item_total": "5543"
                }
          ],
          "total_discount": "532.60",
          "total_sub": "7673.4",
          "total_tax": "537.138",
          "total": "8210.538"
        }
]

The data is part of an JSON array. The array contains 1 top level entry and this entry has two items in the merge block item. The following sample JSON structure contains 2 top level array entries that produces 2 resulting documents:

[
        {
          "yourcompany_companyname": "Text Control, LLC",
          "yourcompany_zip": "28226"
        },
        {
          "yourcompany_companyname": "Text Control GmbH",
          "yourcompany_zip": "28217"
        }
]

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Cloud

Are we moving to the cloud? This question is changing from "if" to "when" and "how". Text Control ReportingCloud brings complete reporting functionality to the cloud so all developers can use it, irrespective of the platform or language they're using. Its highly RESTful API can be used to merge Microsoft Word compatible templates with JSON data from all clients including .NET, Javascript, PHP, Node.JS, jQuery, Ruby, Python, Android, Java and iOS.

See Cloud products

Related Posts

CloudReportingMail Merge

ReportingCloud: Uploading Templates Vs. Sending Templates Inside MergeBody

ReportingCloud offers two template delivery methods: uploading to persistent storage via the /templates/upload endpoint, or embedding Base64-encoded template data in the MergeBody POST request.…


CloudReportingMail Merge

MailMerge: Table Headers and Repeating Blocks

Repeating table headers appear at the top of each page when tables span multiple pages during a MailMerge process. When combining table headers with nested merge blocks, the complete table must be…


CloudReportingMail Merge

ReportingCloud: Conditional Text Blocks Based on Merge Blocks

Conditional text rendering in ReportingCloud uses merge blocks combined with the RemoveEmptyBlocks setting. When the data source provides an empty object for a named block and RemoveEmptyBlocks is…


CloudReportingMail Merge

Web API Test Sandbox Released on ReportingCloud Portal

The ReportingCloud portal includes a Web API Test Sandbox for running endpoint calls against your own account data and template storage without affecting document quota. Each endpoint in the Web…


CloudReportingMail Merge

ReportingCloud: New Test Parameter for Document Quota Related Endpoints

ReportingCloud merge, convert, and findandreplace endpoints now accept an optional test parameter. Test calls bypass the document quota and produce watermarked output with a TEST MODE label,…

Share on this blog post on: