Using JMESPath expressions

Use JMESPath expressions to map and transform JSON response from webhook action into the desired data structure.

Example of using JMESPath expression in your output attributes mapping

Be aware of the following:

  • If your JMESPath expression is incorrect or points to non-existent fields, the output attribute value will be empty.

  • If the resulting value of your JMESPath does not match the target attribute type, the attribute value will also be empty.

Resources on JMESPath:

Examples

Select a Single Field

Input JSON
JMESPath
{
  "name": "Alice",
  "age": 30,
  "city": "London"
}

Expression: name Output:

Alice

Access Nested Fields

Input JSON
JMESPath
{
  "user": {
    "profile": {
      "name": "Charlie",
      "location": "London"
    }
  }
}

Expression: user.profile.location Output:

London

Select Multiple Fields

Input JSON
JMESPath
{
  "id": 123,
  "name": "Bob",
  "email": "[email protected]",
  "age": 25
}

Expression: {name: name, email: email} Output:

{
  "name": "Bob",
  "email": "[email protected]"
}

Select all array element's properties

Input JSON
JMESPath
{
  "products": [
    {"name": "Laptop", "price": 999},
    {"name": "Mouse", "price": 25},
    {"name": "Keyboard", "price": 75}
  ]
}

Expression: products[*].name Output:

[
  "Laptop",
  "Mouse",
  "Keyboard"
]

Filter array by condition

Input JSON
JMESPath
{
  "items": [
    {"name": "Apple", "price": 1.5, "inStock": true},
    {"name": "Banana", "price": 0.8, "inStock": false},
    {"name": "Orange", "price": 2.0, "inStock": true}
  ]
}

Expression: items[?inStock == `true`] Output:

[
  {"name": "Apple", "price": 1.5, "inStock": true},
  {"name": "Orange", "price": 2.0, "inStock": true}
]

Select root-level array

Input JSON
JMESPath
[
  {"id": 1, "name": "Alice", "role": "admin"},
  {"id": 2, "name": "Bob", "role": "user"},
  {"id": 3, "name": "Charlie", "role": "user"}
]

Expression: @ Output:

[
  {"id": 1, "name": "Alice", "role": "admin"},
  {"id": 2, "name": "Bob", "role": "user"},
  {"id": 3, "name": "Charlie", "role": "user"}
]

Use bult-in functions

Input JSON
JMESPath
{
  "items": [
    {"name": "Apple", "price": 15 },
    {"name": "Banana", "price": 999 },
    {"name": "Orange", "price": 75 }
  ]
}

Expression: max(products[*].price) Output:

999

Select array elements for a form message with dynamic data

You can create a from message with dynamic data retrieved from a webhook action. For example:

Input JSON
JMESPath
{
  "products": [
    {"sku": "LAP-001", "name": "Laptop", "price": 999},
    {"sku": "MOU-002", "name": "Mouse", "price": 25},
    {"sku": "KEY-003", "name": "Keyboard", "price": 75}
  ]
}

Expression: products[*].{key: sku, value: name} Output:

[
  {"key": "LAP-001", "value": "Laptop"},
  {"key": "MOU-002", "value": "Mouse"},
  {"key": "KEY-003", "value": "Keyboard"}
]

This can then be used as a data source for your searchable select in a form message.

Last updated