Deep Merge
Overview
Deep Merge merges the enumerable properties of two or more objects deeply.
The step is based on the deepmerge library.
Configuration
Objects to merge (objectPaths)- Array of doc node paths to merge.Object path (objectPaths.objectPath)
Custom function options (customFunctionOptionKey)- Function to apply to merge. Choose 'customMerge' to override default merge behavior, 'arrayMerge' to specify how arrays are merged, or 'isMergeableObject' to control cloning/copying behavior.Custom merge function (customMergeFunction)- Function which can be used to override the default merge behavior for a property, based on the property name (e.g(key) => {if (key === "key") { return () => {}}}))Target path (targetPath)-docnode on which to store the merge result
customMerge
Specifies a function which can be used to override the default merge behavior for a property, based on the property name.
If no function is provided uses the default behavior.
arrayMerge
There are multiple ways to merge two arrays, choosing this option will allow you to specify how to merge arrays.
isMergeableObject
By default, deepmerge clones every property from almost every kind of object.
You may not want this, if your objects are of special types, and you want to copy the whole object instead of just copying its properties.
You can accomplish this by passing in a function for the isMergeableObject option.
Examples
Input
{
"garden": {
"flowers": ["roses", "tulips"]
},
"yard": {
"flowers": ["roses", "tulips", "orchids"]
}
}
Step configuration
| Input | Value |
|---|---|
| path | garden |
| path | yard |
| Custom Function Options | customMerge |
| Function | undefined |
| Target path | result |
Result
{
"doc": {
"garden": {
"flowers": ["roses", "tulips"]
},
"yard": {
"flowers": ["roses", "tulips", "orchids"]
},
"result": {
"flowers": ["roses", "tulips", "roses", "tulips", "orchids"]
}
},
"errors": []
}
Example flow
Sample Deep Merge flow
tags: []
steps:
- stepType: deep-merge
config:
customFunctionOptionKey: customMerge
objectPaths:
- objectPath: garden
- objectPath: yard
targetPath: result
name: Deep Merge
description: ""
condition: ""
sampleData:
garden:
flowers:
- roses
- tulips
yard:
flowers:
- roses
- tulips
- orchids