Stay organized with collections
Save and categorize content based on your preferences.
Takes two maps, creates a copy of the first map, and recursively adds items from the second map to the copy.
For maps with the same key, the value from the first map is replaced by the
value from the second map.
For example, if you have map1 = {key1: value1} and map2 = {key1: value2},
map.merge_nested(map1, map2) returns {key1: value2}.
For nested maps, values are merged recursively.
For example, if you have map1 = {key1: {keyx: valuex}} and
map2 = {key1: {keyy: valuey}}, map.merge_nested(map1, map2) returns
{key1: {keyx: valuex, keyy: valuey}}.
Arguments
Arguments
first
The map to be merged into.
second
The map to merge.
Returns
A copy of the first map with items added from the second map.
Raised exceptions
Exceptions
TypeError
If first or second is not a map (dictionary).
Examples
# Recursively add items from second map to copy of first map# Returns `{"key1": {"key2": "value2","key3": "value3"}}`-init:assign:-my_map1:{"key1":{key2:value2}}-my_map2:{"key1":{key3:value3}}-returnStep:return:${map.merge_nested(my_map1, my_map2)}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Function: map.merge_nested\n\nTakes two maps, creates a copy of the first map, and recursively adds items from the second map to the copy.\n\nFor maps with the same key, the value from the first map is replaced by the\nvalue from the second map.\n\nFor example, if you have `map1 = {key1: value1}` and `map2 = {key1: value2}`,\n`map.merge_nested(map1, map2)` returns `{key1: value2}`.\n\nFor nested maps, values are merged recursively.\n\nFor example, if you have `map1 = {key1: {keyx: valuex}}` and\n`map2 = {key1: {keyy: valuey}}`, `map.merge_nested(map1, map2)` returns\n`{key1: {keyx: valuex, keyy: valuey}}`.\n\nArguments\n---------\n\nReturns\n-------\n\nA copy of the first map with items added from the second map.\n\nRaised exceptions\n-----------------\n\nExamples\n--------\n\n```yaml\n# Recursively add items from second map to copy of first map\n# Returns `{\"key1\": {\"key2\": \"value2\",\"key3\": \"value3\"}}`\n- init:\n assign:\n - my_map1: {\"key1\": {key2: value2}}\n - my_map2: {\"key1\": {key3: value3}}\n- returnStep:\n return: ${map.merge_nested(my_map1, my_map2)}\n```"]]