right_join
Joins two arrays based on matching keys, similar to SQL RIGHT JOIN. All items from the second array are kept, with matching properties merged from the first array. Non-matching items get null values for the first array's properties.
{% json employees %}
[
{ "id": 1, "name": "Ann", "department_id": 10 },
{ "id": 2, "name": "Adam", "department_id": 20 }
]
{% endjson %}
{% json departments %}
[
{ "dept_id": 10, "dept_name": "Accounting", "floor": 3 },
{ "dept_id": 20, "dept_name": "Sales", "floor": 5 },
{ "dept_id": 30, "dept_name": "Marketing", "floor": 7 }
]
{% endjson %}
{% assign result = employees | right_join: departments, "department_id = dept_id" %}
{% log result %}Results in following output:
[
{
"dept_id": 10,
"dept_name": "Accounting",
"floor": 3,
"id": 1,
"name": "Ann",
"department_id": 10
},
{
"dept_id": 20,
"dept_name": "Sales",
"floor": 5,
"id": 2,
"name": "Adam",
"department_id": 20
},
{
"dept_id": 30,
"dept_name": "Marketing",
"floor": 7,
"id": null,
"name": null
}
]Syntax
Parameter
Description
array1
Array to join from
array2
Primary array (all items kept)
key1
Property name in array1 to match
key2
Property name in array2 to match
Notes
Modifies
array2in placeUnmatched items receive
nullfor properties fromarray1(excluding the join key)See also:
left_joinfor keeping all items from the first array instead
Last updated