The block "Merge lists" will merge two given lists (arrays) into one new list.

The block takes 2 lists as input:

The items of both input lists will be added to the new output list. Items will be matched based on a given key. If the value is the same, both items will be merged into one new item.

Example list 1:

[
      {"email": "john@doe.com", "name": "John Doe"},
      {"email": "bill@acme.com", "name": "Bill Davis"}
]

Example list 2:

[
      {"email": "john@doe.com", "city": "NY"},
      {"email": "ann@acme.com", "city": "Paris"}
]

Example settings:

Item merge strategy

Merge list 1 item and list 2 item in one new item

All key/values from the object of both lists will be merged into one new object. For the above example lists, the first merged object will be: 

{"email": "john@doe.com", "name": "John Doe", "city": "NY"}

Add list 2 items as children to list 1 items

Use this for a parent/child relationship, e.g. customers (parent) and orders (children). All matching objects from list 2 will be added as an array under one key in the object from list 1.

Let's assume list 2 looks like this:

[
    {"id": 1, "price": 100, "email": "john@doe.com"},
    {"id": 2, "price": 200, "email": "john@doe.com"}
]

The resulting first object in the merged list will be:

{
  "email": "john@doe.com",
  "name": "John Doe",
  "orders": [ {"id": 1, "price": 100}, {"id": 2, "price": 200} ]
}

Unique key

Choose a key from the objects in each list to compare values. For example "email" in one list and "profile.email" in the second. Objects will be matched/merged based on the values from these keys.

On duplicate unique key

Ignore item from list 2

The object of list 2 will be ignored, when it matches an object of list 1. For the above example lists, the result will be:

[
      {"email": "john@doe.com", "name": "John Doe"},
      {"email": "bill@acme.com", "name": "Bill Davis"},
      {"email": "ann@acme.com", "city": "Paris"}
]

Merge item from list 2 into item from list 1

The object of list 2 will be merged with the object from list 1. For the above example lists, the result will be:

[
      {"email": "john@doe.com", "name": "John Doe", "city": "NY"},
      {"email": "bill@acme.com", "name": "Bill Davis"},
      {"email": "ann@acme.com", "city": "Paris"}
]

Merge values case-insensitive

If checked, the values will be compared case-insensitive

Iterator

This block does not use an iterator, which means that both input lists will be loaded in memory before doing the merge. This means that a Blend using this block will fail with an "out of memory" error for very large lists.

Did this answer your question?