- 17 Nov 2023
-
DarkLight
-
PDF
merge
- Updated on 17 Nov 2023
-
DarkLight
-
PDF
Task Purpose
The merge task allows you to combine data from job variables, static data, and the outgoing variables of tasks to create a new variable. By merging data, you can create new data structures to match the existing parameters of a task, thereby allowing you to reuse existing tasks without programming new tasks. A merge task can combine number, boolean, string, array, and object data types.
When merging data, one of two assignment modes are supported: no keys or unique keys.
Mode | Description |
---|---|
No keys assigned to merged data | The merge task returns an array of the merged values in a non-deterministic order. See the examples below. |
Unique keys assigned to merged data | The merge task returns an object with key/value fields as specified. See the examples for this task. |
The merge task does not support merging data with partial key assignments or non-unique keys.
Properties
Property | Description |
---|---|
Key (optional) | Specify a key for each merged value. Supported configurations are either no keys or all unique keys. |
Task (required) | Specify where to find a variable to merge. You can merge data stored in job variables, a static value, or the outgoing variable of an earlier task. |
Variable | Specify the data to merge in the Variable field. When the data comes from the job or an earlier task, select the variable from the dropdown list. If the data comes from a static value, type the value in the variable edit box. |
How to Configure
First, create a three-element array by merging data returned from three different tasks, and let's assume the tasks return these objects:
{
"vendor": "Cisco",
"platforms": [ "3945", "6500" ],
"chassis": [ "fixed", "modular" ]
}
{
"release": "15.5"
}
{
"features": [ "L3VPN", "STP" ]
}
No Keys Assigned
Next, configure the merge task properties with no keys as shown in the datasets below (Figures 1 - 3).
Figure 1: Vendor, Platforms & Chassis Dataset
Figure 2: Release Data
Figure 3: Features Dataset
The merge task returns an array and the order is not deterministic.
Figure 4: Outgoing Array
Unique Keys Assigned
Next, create an object by assigning unique keys to each merged value. In addition to the three objects used in the previous example, the merge includes a number
, string
, boolean
, and array
.
Configure the merge task properties with unique keys as shown in the datasets below (Figures 5 - 8).
Figure 5: Number
Figure 6: String
Figure 7: Boolean
Figure 8: Array
The merge task returns this object of specified key/value fields.
{
"merged_object": {
"chassis": {
"vendor": "Cisco",
"platforms": [
"3945",
"6500"
],
"chassis": [
"fixed",
"modular"
]
},
"os-image": {
"release": "15.5"
},
"services": {
"features": [
"L3VPN",
"STP"
]
},
"number": {
"myNumber": 13
},
"string": {
"myString": "hello world"
},
"boo": {
"myBoolean": true
},
"arr": {
"myArray": [
"apple",
"pear"
]
}
}
}
Reference
For related information, see the merge API reference.