Did you already know that Alumio supports the JMESPath query language? This enables you to manipulate your data even easier than before, as this allows you to execute code-like methods directly on your data.
Let me provide you with two examples!
Sorting lists
Let’s assume we have the following data:
{
"unsorted_list": [10,6,8,12]
}
In order to sort this list, we can use the *sort function (*documentation: JMESPath Specification — JMESPath) to let JMESPath automatically sort this for us. The sample configuration is shown in the image below.
The result is as follows:
{
"unsorted_list": [10, 6, 8, 12],
"sorted_list": [6, 8, 10, 12]
}
Filtering an array of objects
For this example, we will assume the following data:
{
"api": [{
"type": "rest",
"name": "Magento 2.4"
},
{
"type": "soap",
"name": "Magento 1.9"
},
{
"type": "rest",
"name": "Shopware 6.4"
}
]
}
Then, sometimes we just need a value of the specific field, let’s say the value of the key name, and want to ignore the others. You can achieve it by this:
Results:
{
"api": [
"Magento 2.4",
"Magento 1.9",
"Shopware 6.4"
]
}
Now, if we only want to keep the API objects where the type equals rest, we can utilize the filtering capability of JMESPath (documentation can be found here: JMESPath Examples — JMESPath) by applying the following transformation:
This brings us the following result:
{
"api": [{
"type": "rest",
"name": "Magento 2.4"
},
{
"type": "rest",
"name": "Shopware 6.4"
}
]
}
Then you will also be able to get data from a specific key; for example, you will only get the value of the filtered data’s name.
The result should be like this:
{
"api": [
"Magento 2.4",
"Shopware 6.4"
]
}
Extracting and transforming data with multiselect
In some situations, we do not only want to filter data or extract a single value, but also create a new structure based on the existing input. This can be done by using a multiselect object in JMESPath.
Let us use the following data:
{
"api": [{
"type": "rest",
"name": "Magento 2.4"
},
{
"type": "soap",
"name": "Magento 1.9"
},
{
"type": "rest",
"name": "Shopware 6.4"
}
]
}
Now, let us assume we want to keep the original API data but transform each object into a simpler structure that contains only the API name and API type.
This can be achieved by using the following method:
This expression loops through each object in the api array and creates a new object for each item:
-
api_namewill contain the value ofname -
api_typewill contain the value oftype
The result will look as follows:
{
"api": [
{
"api_name": "Magento 2.4",
"api_type": "rest"
},
{
"api_name": "Magento 1.9",
"api_type": "soap"
},
{
"api_name": "Shopware 6.4",
"api_type": "rest"
}
]
}
Comparing Values
JMESPath supports common comparison operators, such as below.
==(equals)!=(doesn’t equal)<(is less than)<=(is less than or equal to)>, (is greater than)>=(is greater than or equal to)
Let’s assume we have the following data.
{
"val1": "foo",
"val2": "bar",
"val3": "baz"
}
In order to check whether the property val1 equals to foo You can create a property called result, such as below.
The value of the result property will be true because the value of the property val1 does indeed equal to foo.
{
"val1": "foo",
"val2": "bar",
"val3": "baz",
"result": true
}
In addition to the comparators, JMESPath provides the ability to use logical expressions, such as below.
&&(AND expression),||(OR expression),!(NOT expression),(...)(Paren expressions)
By using the same data as the previous example, we want to check multiple conditions, such as below.
The conditions are val1 equals to foo AND val2 equals to bar, then, the result of previous conditions OR val3 doesn’t equal to baz. We will need the below JMESPath syntax.
&{(val1 == 'foo' && val2 == 'bar') || val3 != 'baz'}
The result of the above syntax is true because the result of conditions in the parenthesis is true. Therefore, it doesn’t matter what is the result of the last condition (because it uses OR expression), the final result will be true.
Hopefully this information helped you understanding the basics of JMESPath. More information can be found over at https://jmespath.org/.
Best of luck implementing this within your integrations and feel free to share your own JMESPath tips and tricks below!





