deepmerge
  • 23 May 2023
  • Dark
    Light
  • PDF

deepmerge

  • Dark
    Light
  • PDF

Article summary

deepmerge Task Purpose

The deepmerge task folds two or more objects together to create a single object with the precedent that the last merged object is used if a conflict occurs. It allows for combining objects, for example parts of a service instance, into an object representing a whole service instance. The task can create new data structures to match an existing task's parameters, which allows us to reuse existing tasks without new programming. A deepmerge task can combine data from job variables, static data, and tasks' outgoing variables, but 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. See the examples below to illustrate various merge outcomes.

The deepmerge task merges elements at any depth.

Properties

Property Description
Key The key field is not 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 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.
Add/Remove/Reorder Add, remove, and reorder the merged data.

Control Buttons

Control Icon Function
Add row + Add a row below the relevant row.
Delete row - Remove a row.
Move row up Up Arrow Button Move row up one row.
Move row down Down Arrow Button Move row down one row.

Example 1

Given the following objects.

Object 1

{
    "customer": "Wet Paint"
}

Object 2

{
    "service": "L3VPN"
}

Object 3

{
    "active": true
}

Result

The result will be.

{
    "customer": "Wet Paint",
    "service": "L3VPN",
    "active": true
}

Example 2

Given the following objects.

Object 1

{
    "fruit": {
        "apple": {
            "shape": {
                "round": {
                    "red": {
                        "flavor": "sweet"
                    }
                }
            }
        }
    }
}

Object 2

{
    "fruit": {
        "apple": {
            "shape": {
                "round": {
                    "red": {
                        "ripe": false
                    }
                }
            }
        }
    }
}

Object 3

{
    "fruit": {
        "apple": {
            "shape": {
                "round": {
                    "red": {
                        "quantity": 32
                    }
                }
            }
        }
    }
}

Result

The result will be.

{
    "fruit": {
        "apple": {
            "shape": {
                "round": {
                    "red": {
                        "flavor": "sweet",
                        "ripe": false,
                        "quantity": 32
                    }
                }
            }
        }
    }
}

Conflicting Key Example 1

Given the following objects.

Object 1

{ "fruit": "apple" }

Object 2

{ "fruit": 20 }

Result

The result will be.

{ "fruit": 20" }

Conflicting Key Example 2

Given the following objects.

Object 1

{
    "fruit": [
        {
            "name": "apple"
        }
    ]
}

Object 2

{
    "fruit": [
        {
            "name": "orange"
        }
    ]
}

Result

The result will be.

{
    "fruit": [
        {
            "name": "orange"
        }
    ]
}

Non-conflicting Key Example

The following example does not have a key conflict.

Object 1

{
    "quantity": [
        {
            "name": "apple"
        }
    ]
}

Object 2

{
    "quantity": [
        {
            "color": "red"
        }
    ]
}

Result

The result will be.

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

Was this article helpful?

What's Next
Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.