left_join
Merges two arrays of objects based on matching keys, similar to a SQL LEFT JOIN. Each item in the first array is enriched with properties from the matching item in the second array. Items without a match get null values for the second array's properties.
{% assign enriched = orders | left_join: customers, "customer_id = id" %}
{% for order in enriched %}
{% log order.name | append: " - " | append: order.email %}
{% endfor %}Syntax
{{ array1 | left_join: array2, expression }}array1
Primary array (left side) — all items are preserved
array2
Secondary array (right side) — properties are merged into matching items
expression
Join condition in the format "key1 = key2" where key1 is from array1 and key2 is from array2
Return Value
Returns the first array with properties from the second array merged into each item. Items in the first array that have no match in the second array receive null for the second array's properties.
Examples
Enrich orders with customer data:
{% assign enriched_orders = orders | left_join: customers, "customer_id = id" %}
{% for order in enriched_orders %}
{% log order.name | append: " | Customer: " | append: order.first_name | append: " " | append: order.last_name %}
{% endfor %}Match import data with existing products by SKU:
Combine inventory levels with variant data:
Merge CSV data with API results:
How it works
Notes
The expression format is
"key_from_array1 = key_from_array2"— spaces around=are requiredBoth inputs must be arrays — throws an error otherwise
Modifies the first array in place — properties from matching items in the second array are merged directly
Uses O(n + m) performance via internal Map lookup, not O(n * m)
Items without a match receive
nullfor all properties from the second array (except the join key)If multiple items in the second array share the same key, the last one is used
See also:
right_join,index_by
Last updated