deepmerge

The deepmerge task folds two or more objects together to create a single object. When a conflict occurs, the value from the last merged object takes precedence. The task allows combining objects — for example, parts of a service instance into an object representing a whole service instance — and can create new data structures to match an existing task’s parameters, enabling reuse of existing tasks without new programming.

A deepmerge task can combine data from job variables, static data, and tasks’ outgoing variables. This task only operates on objects — it does not operate on numbers, booleans, strings, or arrays.

When merge conflicts occur, the conflicting key’s value in the last merged object is used. The deepmerge task merges elements at any depth.

Properties

PropertyDescription
KeyNot used and will be ignored.
Task (required)Specify where to find a variable to merge. You can merge data stored in job variables, a static value, or an earlier task’s outgoing variable.
Variable (required)Specify the data to merge. 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.
Add/Remove/ReorderAdd, remove, and reorder the merged data.

Control buttons

ControlFunction
Add row (+)Add a row below the relevant row.
Delete row (−)Remove a row.
Move row up (↑)Move a row up one position.
Move row down (↓)Move a row down one position.

Examples

Merge three flat objects

Object 1

1{ "customer": "Wet Paint" }

Object 2

1{ "service": "L3VPN" }

Object 3

1{ "active": true }

Result

1{
2 "customer": "Wet Paint",
3 "service": "L3VPN",
4 "active": true
5}

Merge deeply nested objects

Object 1

1{
2 "fruit": {
3 "apple": {
4 "shape": {
5 "round": {
6 "red": { "flavor": "sweet" }
7 }
8 }
9 }
10 }
11}

Object 2

1{
2 "fruit": {
3 "apple": {
4 "shape": {
5 "round": {
6 "red": { "ripe": false }
7 }
8 }
9 }
10 }
11}

Object 3

1{
2 "fruit": {
3 "apple": {
4 "shape": {
5 "round": {
6 "red": { "quantity": 32 }
7 }
8 }
9 }
10 }
11}

Result

1{
2 "fruit": {
3 "apple": {
4 "shape": {
5 "round": {
6 "red": {
7 "flavor": "sweet",
8 "ripe": false,
9 "quantity": 32
10 }
11 }
12 }
13 }
14 }
15}

Conflicting key — scalar value

When the same key exists in both objects with different scalar values, the last object’s value wins.

Object 1

1{ "fruit": "apple" }

Object 2

1{ "fruit": 20 }

Result

1{ "fruit": 20 }

Conflicting key — array value

When the same key exists in both objects with array values, the last object’s array replaces the first.

Object 1

1{
2 "fruit": [{ "name": "apple" }]
3}

Object 2

1{
2 "fruit": [{ "name": "orange" }]
3}

Result

1{
2 "fruit": [{ "name": "orange" }]
3}

Non-conflicting key — array value

When the same key exists in both objects but the array items have different keys, the items are merged.

Object 1

1{
2 "quantity": [{ "name": "apple" }]
3}

Object 2

1{
2 "quantity": [{ "color": "red" }]
3}

Result

1{
2 "quantity": [{ "name": "apple", "color": "red" }]
3}