Use JSONata expressions in data mappings inside the Product sync module to transform your commercetools product data into the format required by the AI provider.
Each expression is evaluated against a single entry in the product feed. Expressions can access product fields directly, apply conditional logic, and call built-in helper functions called bindings.
Product data object
productData: the ProductProjection for the current product. InproductData, themasterVariantandvariantsfields contain only theid,key, andskuof each Product Variant.variant: the Product Variant that this feed entry represents, with all of its fields.store: the Store of the Agentic Channel.shippingMethods: the ShippingMethod resources that match the country of the Agentic Channel, with thezoneof each Zone rate expanded.
price field (singular). For mapping expressions, prefer variant.price over the variant.prices array as the price source.categories[*].ancestors[*], and the discount of the scoped price of each Product Variant. To expand additional references, add them as Product Expansions in the data mapping configuration.The following simplified example shows the structure of a single feed entry. Fields not relevant to data mapping are omitted.
{
"productData": {
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"name": { "en-US": "Classic Running Shoe", "de-DE": "Klassischer Laufschuh" },
"description": { "en-US": "A versatile everyday running shoe." },
"slug": { "en-US": "classic-running-shoe" },
"masterVariant": {
"id": 1,
"key": "classic-running-shoe-master",
"sku": "CRS-001-BLK-42"
},
"variants": [
{
"id": 2,
"key": "classic-running-shoe-v2",
"sku": "CRS-001-BLK-43"
}
]
},
"variant": {
"id": 1,
"key": "classic-running-shoe-master",
"sku": "CRS-001-BLK-42",
"price": {
"id": "a1b2c3d4-5678-4abc-b3fc-2c963f66afa6",
"value": { "centAmount": 12999, "currencyCode": "USD", "fractionDigits": 2 },
"channel": { "id": "956d220a-fde7-44be-8496-c852fed723ca" }
},
"attributes": [
{ "name": "color", "value": "black" },
{ "name": "size", "value": 42 }
],
"availability": {
"channels": {
"inventory-channel-id": {
"isOnStock": true,
"availableQuantity": 100
}
}
}
},
"store": {
"id": "store-ABC"
},
"shippingMethods": [
{
"id": "sm-standard"
},
{
"id": "sm-express"
}
]
}
This example shows how multiple resources are combined in a single feed entry. For full field-level details, refer to the API type definitions:
productDatafollows the ProductProjection shape.variantfollows the ProductVariant shape.storefollows the Store shape.shippingMethodscontains ShippingMethod resources.
Default bindings
Variable bindings
The following variable bindings are available in every expression. Their values are derived from the configuration of your Agentic Channel, and cannot be reassigned. They are always injected and read-only.
| Binding | Type | Example value | Description |
|---|---|---|---|
$country | string | "US" | Country configured for the Agentic Channel. |
$locale | string | "en-US" | Locale configured for the Agentic Channel. |
$storeKey | string | "us-store" | Key of the Store of the Agentic Channel. |
Function bindings
The default templates of all providers include the following function bindings. You can modify or remove them, and add your own.
| Binding | Description |
|---|---|
$tail(array) | Returns the array without its first item. For example, $join($tail(variant.images).url, ",") lists all images except the first. |
$getAttribute(attributes, name) | Returns the value of a named attribute from a variant's attributes array. |
$priceToAmount(money) | Returns the numeric amount of a TypedMoney value, such as variant.price.value, accounting for fractionDigits. Supports both cent precision and high precision money values. Returns an empty string if there is no price. |
$formatPrice(amount, money) | Returns the amount formatted with the number of fraction digits of the money value, followed by its currency code (for example, "129.99 USD"). |
$storeBaseUrl(store) | Returns the base URL of the storefront. Uses the sellerStoreUrl Custom Field of the Store if set. Otherwise, returns the origin of the Store's storefront.orderUrlTemplate or storefront.checkoutUrlTemplate. |
$tail(array) | Returns all elements of an array except the first one, for example, to list additional images. |
Expression examples
The following examples show expressions of increasing complexity, from direct field access to derived transformations.
Access fields directly
The simplest expressions access a field directly from the product entry.
variant.sku
Localized fields are plain objects keyed by locale. Use a string key with backticks when the locale contains a hyphen.
productData.name.`en-US`
productData.id
Use bindings and conditionals
Intermediate expressions use bindings, conditionals, or string operations.
$locale variable binding and $lookup to access the localized value dynamically, without hardcoding a language.$lookup(productData.name, $locale)
variant.availability.channels and keyed by inventory Channel ID. Stock that has no supply Channel is in the top-level variant.availability.isOnStock field. A variant without inventory has no availability. The Google default template maps a variant to "in_stock" if any Channel has stock, and to "out_of_stock" otherwise. The OpenAI default template does the same, but uses the top-level isOnStock value when the variant has no Channels.variant.availability.channels ? ($count(variant.availability.channels.*[isOnStock=true]) > 0 ? "in_stock" : "out_of_stock") : "out_of_stock"
This expression counts stock in every inventory Channel. To use the top-level value when the variant has no Channels, add a fallback:
variant.availability.channels ? ($count(variant.availability.channels.*[isOnStock=true]) > 0 ? "in_stock" : "out_of_stock") : (variant.availability.isOnStock ? "in_stock" : "out_of_stock")
$getAttribute to retrieve a named attribute from the variant's attributes array.$getAttribute(variant.attributes, "color")
Build derived values
Complex expressions combine multiple fields, optional helper functions, and logic to produce derived values.
$priceToAmount with the money value of the scoped price to correctly account for the currency's fractionDigits value.$priceToAmount takes the price value object and accounts for the currency's fractionDigits value.variant.price ? $priceToAmount(variant.price.value) : ""
$power fail and stops the export.variant.price ? variant.price.value.centAmount / $power(10, variant.price.value.fractionDigits) : ""
$formatPrice. The default templates use the JSONata chain operator ~> to pass the result of $priceToAmount as the first argument. The result includes the currency code, for example "79.99 EUR".variant.price ? $priceToAmount(variant.price.value) ~> $formatPrice(variant.price.value) : ""
variant.price.discounted.variant.price.discounted ? $priceToAmount(variant.price.discounted.value) ~> $formatPrice(variant.price.discounted.value) : ""
Combine the localized product name with custom attribute values to produce a richer title string.
$lookup(productData.name, $locale) & " - " & $getAttribute(variant.attributes, "color") & " / " & $string($getAttribute(variant.attributes, "size"))
Argument 2 of function "power" does not match function signature. Select Open data mapping, fix the expression, and export again.Each provider validates empty fields and wrong formats on its own side, and AI Hub doesn't show the results of that validation. A provider can skip a product that fails its checks:
- Google skips a product that has an empty ID.
- OpenAI skips a variant that has no price in the configured currency.
Check the required fields on the provider's product data page before you sync. After a sync, check the provider's dashboard for validation errors, and fix them in your data mapping.
$exists(value) ? value : fallback. JSONata does not provide a $default operator.Next steps
- To check an expression against a sample product on your computer, see Test JSONata locally.
- To draft expressions with an LLM, see Generate a data mapping with AI.