When your source record contains an array of items, you can map each item to its own object in the destination array. This article is for builders who need to map order lines, contacts, or other repeating items in Mapper 2.0, and who also need to include a field from outside the array in every item.
Syntax
| Syntax | Use it to | Example |
|---|---|---|
[*] |
Select every item in the source array. Add it to the parent array field. | $.items[*] |
@. |
Select a field of the current item. Use it on the child fields. | @.items.description |
$. |
Select a field anywhere in the source record. | $.orderId |
Add [*] only to the array field. Don't add it to the child fields. Use @. with dot notation to select each child field.
Map each item in an array
This example maps the items in an order to a destination items array, and adds the order ID to each item.
Source data:
{
"orderId": 123,
"total": 99.99,
"state": "ca",
"items": [
{ "description": "Hat", "qty": 3 },
{ "description": "Shoes", "qty": 1 }
]
}Required destination structure:
{
"items": [
{ "description": "Hat", "quantity": 3, "orderID": 123 },
{ "description": "Shoes", "quantity": 1, "orderID": 123 }
]
}- Add the destination field
itemswith data type object array. For the source, enter$.items[*]. - Under
items, add the fielddescriptionwith data type string. For the source, select@.items.description. - Add the field
quantitywith data type number. For the source, select@.items.qty. - Add the field
orderIDwith data type number. For the source, select$.orderId.
Each source item produces one destination object. The orderID field comes from outside the array, so every object gets the same value.
To number the items, see Mapper 2.0 examples.