Target field | Mapping expression |
---|---|
phone_number | telephone |
phone_number
. In this case, the mapping expression is simply the name of a field in the source.
Target field | Mapping expression |
---|---|
phone_number | business.contact.telephone |
orders
. In the mappings UI, the field is marked with the word array, which is another word for list. In the source, the list that contains the relevant data has the path transaction.order.products
, so that’s the mapping expression you need for orders
.
Specify a mapping expression for each field in orders
. For example, the field product_number
is called id
in the source.
Target field | Mapping expression |
---|---|
orders | transaction.order.products |
product_number | id |
quantity | amount |
unit_price | price.unit |
transaction.order.products
, because Mappings knows that those fields are relative to the context of the list. For that reason, the mapping expression for a list is referred to as a list context.
index
property:
Source
index
field. Positional variables in JSONata are zero-based.
Target field | Mapping expression |
---|---|
orders | transaction.order.products#$myIndex |
product_number | id |
index | $myIndex + 1 |
quantity | amount |
unit_price | price.unit |
index
property is successfully populated for every item in the Output JSON document. This approach could create output like the following example.
Target field | Mapping expression |
---|---|
product_numbers | products.id |
[]
at the end of the mapping expression. The following example shows the new output.
order
object.
Target field | Mapping expression |
---|---|
order | |
product_number | product.id |
quantity | product.amount |
unit_price | product.price.unit |
order
level, so all of its children have to specify a path relative to the root of the source document.
order
, and remove the common part of the path from expressions of its child fields.
Target field | Mapping expression |
---|---|
order | product |
product_number | id |
quantity | amount |
unit_price | price.unit |
LV-
prefix.
Target field | Mapping expression |
---|---|
order | products[$startsWith(id, "LV-")] ~> $single |
product_number | id |
quantity | amount |
unit_price | price.unit |
0
, a certain object should not be populated in the output.
Source
order
object from the output, you should provide a ternary condition as an optional object context, and return $omitField
when zero products were found in the source.
When the omitting condition is not met, you can pass down the parent context variable $
, which in this case would evaluate to the whole source document, the same as not providing and object context at all.
Target field | Mapping expression |
---|---|
customer_name | customer |
order | $count(products) = 0 ? $omitField : $ |
quantity | $count(products) |
total_price | $sum(products.price.total) |
$number
function.
Source
Target field | Mapping expression |
---|---|
quantity | $number(quantity) |
$string
function. String is another word for text.
Source
Target field | Mapping expression |
---|---|
quantity | $string(quantity) |
*
, /
, +
, and -
.
Source
Target field | Mapping expression |
---|---|
total | price * quantity * discount |
$number
function.
Source
Target field | Mapping expression |
---|---|
total | $number(subtotal) * $number(vat) |
$sum
and $average
.
Source
Target field | Mapping expression |
---|---|
sum | sum(prices) |
average | average(prices) |
Target field | Mapping expression |
---|---|
sum | $sum(orders[].price) |
average | $average(orders[].price) |
price
). Make sure to put []
after the name of the list (orders
) to let Mappings know that you want all prices in the list.
&
.
Source
Target field | Mapping expression |
---|---|
name | first_name & " " & last_name |
$substring
. You need to specify where the part is that you’re interested in, so this only works for text that follows a predictable pattern.
Source
Target field | Mapping expression |
---|---|
area_code | substring(phone_number, 1, 3) |
$substring
know where the part begins, and how many letters you want. $substring
starts counting characters at 0, so in the example above, we start at the second characters.
If the part you’re interested in is at the back of the text, you can use a negative number to tell $substring
to start counting from the last character.
Source
Target field | Mapping expression |
---|---|
local_number | $substring(phone_number, -8. 8) |
$split
.
Source
Target field | Mapping expression |
---|---|
location | $split(location, ", ") |
Target field | Mapping expression |
---|---|
city | $split(location, ", ")[0] |
state | $split(location, ", ")[1] |
country | $split(location, ", ")[2] |
$lookupTable
. For example, you might create a lookup table for country codes and then write the following expression.
Target field | Mapping expression |
---|---|
country_code | $lookupTable($tables.countries, "short" country_code).long |
code
for the country code and symbol
for the currency symbol.
Source
Target field | Mapping expression |
---|---|
name | $lookupTable($tables.currency, "code", currency).name |
symbol | $lookupTable($tables.currency, "code", currency).symbol |
*
symbol (or any other sequence of symbols, you will be able to select what to match against during the $lookupTable
function call).
-> Note: You can replace multiple parts of your key with *
.
Any input value that matches the loosely defined wildcard-based lookup table value is now matched when the { "wildcard": "*" }
is passed as an optional parameter to the $lookupTable
function.
$omitField
constant.totals
object has a mapping expression associated with it, but it still ends up in the output.
Target
Target field | Mapping expression |
---|---|
products | products |
id | id |
quantity | |
price |
totals
to show up at all, select Target keys and deselect the field.
This doesn’t apply when you set the mapping type to Merge with target example, because that option will always copy the values from the the target, unless you use $omitField
.
$omitField
to tell Mappings when to skip the field.
This is particularly useful if the mapping type is set to Merge with target example and you don’t want to use the default value. In the following example, the total price is included only if the amount of products is larger than 0.
Target
Target field | Mapping expression |
---|---|
totalPrice | amount > 0 ? amount * price : $omitField |
unitPrice | price |
$omitField
, the output would’ve included the totalPrice
with its default value of 3000
, which is clearly wrong in this case.
$omitField
in any input field on the Mapping form, including
list context and object context inputs.