The JSON Merge Component is a transformation component used to merge input data into JSON. Define the relationship of inputs in the Design Page, configure column properties in the Columns Page, and refine formatting in the Advanced Page.
Define the relationship of the Inputs in the Design Page.
To define relationships simply click and drag from a child field to a parent field. In the above example, there is a relationship from the Item.PurchaseOrderId field to PurchaseOrder.Id field. What this means when merging is PurchaseOrder nodes will contain Item nodes whose PurchaseOrderId field match the PurchaseOrder's Id field. If you need to remove a relationship on the design page, simply select the connecting arrow and press the 'Delete' key.
You cannot continue to the Columns Page until the relationship structure is valid. The most common cause for an invalid relationship is invalid root count. The root input is defined be an input who does not have a parent Input. There must be one and only one root input. To fix this, delete any unused inputs and adjust the relationships so that there is only one root.
Configure column/node specific merge settings.
Check and uncheck nodes in the data grid to specify if they should be in the merged JSON. A good use for this is to hide the parent Id field in the child. This field is required to merge but not in the JSON because JSON uses hierarchy to define relationships.
NOTE: Checking and unchecking nodes are recursive so you can check and uncheck an entire input of nodes at a time. That being said if you do not want an input to go into the JSON simply disconnect the input altogether. This is better for performance and will make the design and Columns page easier to work with.
To configure node properties, select nodes in the data grid on the left to populate the property grid on the right. In the property grid you can adjust the following:
- JSON Name
Specifies the name of the JSON node.
- JSON Type
There are three different node types an Input node can be:
- Array Of Objects - This will create an object for each record in this input and add it to an array.
- Array Of Values - This will add values directly to the array. Best used when there is only 1 column.
- Object - This will create a single object. Best used when there is only one matching record expected.
NOTE: The root Input node will always be of JSON Type: Object. However, it will add these objects to an array if the Merge Mode setting on the Advanced Page is set to Every Batch or Entire Buffer.
Configure JSON and merge related settings here.
- Null Mode
This property specifies how to handle NULL values. There are three options:
- Don't Show - This option will hide nodes whose values are null.
- Empty String - This option will convert NULL values to an empty string.
- Null Value - This option will write null.
- Print Pretty
When true, the merged JSON will contain line breaks and indents. When false, the merged JSON will be a single line of text.
- Merge Mode
Specify how to merge the inputs into JSON. There are three different Merge Modes:
- Every Row - This creates a JSON document for each record in the root Input. Notice when this option is selected, the columns of the root input are directed to the Default Output.
- Every Batch - This creates a JSON document for every batch. The size of the batch is determined by the Batch Size property, and a batch item is equivalent to one record in the root input. In other words, a batch size of 10 will create JSON documents that each contain 10 root input records.
- Entire Buffer - This creates a single JSON document.
- Batch Size
Specifies how many root input records should be in each JSON document. This option is only available if the Merge Mode is Every Batch.
Output & Error Handling
This page allows you to specify how errors should be handled when they happen along with the name of the output column that will contain the merged JSON.
- Merged JSON Column Name
The name of the output column that will contain the merged JSON.
Error Handling has three options available.
- Fail on error
- Redirect rows to error output
- Ignore error
When the Redirect rows to error output option is selected, rows that failed to be sent will be redirected to the 'Error Output' output of the Transformation Component. As indicated in the screenshot below, the blue output connection represents rows that were successfully sent, and the red 'Error Output' connection represents rows that were erroneous. The 'ErrorMessage' output column found in the 'Error Output' may contain the error message that was reported by the component.