left_join

Joins two arrays based on matching keys, similar to SQL LEFT JOIN. All items from the first array are kept, with matching properties merged from the second array. Non-matching items get null values for the second array's properties.

{% json employees %}                                                                      
  [                                                                                       
    { "id": 1, "name": "Ann", "department_id": 10 },                                      
    { "id": 2, "name": "Adam", "department_id": 20 },                                     
    { "id": 3, "name": "Angela", "department_id": 30 }                                    
  ]                                                                                       
{% endjson %}                                                                             
                                                                                          
{% json departments %}                                                                    
  [                                                                                       
    { "dept_id": 10, "dept_name": "Accounting", "floor": 3 },                             
    { "dept_id": 20, "dept_name": "Sales", "floor": 5 }                                   
  ]                                                                                       
{% endjson %}

{% assign result = employees | left_join: departments, "department_id = dept_id" %}

{% log result %}

Results in following output:

Syntax

Parameter
Description

array1

Primary array (all items kept)

array2

Array to join from

key1

Property name in array1 to match

key2

Property name in array2 to match

Notes

  • Modifies array1 in place

  • Unmatched items receive null for properties from array2 (excluding the join key)

  • See also: right_join for keeping all items from the second array instead

Last updated