Start a new topic

How to use JMESPath to simplify your transformations

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: https://jmespath.org/specification.html#sort) to let JMESPath automatically sort this for us. The sample configuration is shown in the image below.


image




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"
		}
	]
}

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: https://jmespath.org/examples.html#filters-and-multiselect-lists) by applying the following transformation:


image



This brings us the following result:

{
	"api": [{
			"type": "rest",
			"name": "Magento 2.4"
		},
		{
			"type": "rest",
			"name": "Shopware 6.4"
		}
	]
}


 -----


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!


1 person has this question
1 Comment

Hi, Jmespath is really helpful but sometimes you need to have a variable in the jmespath expression. Is there already a way to do this? Example: "&{Products.product."+variable+".sku} Would be great to have an eval function or just plain JavaScript.
Login or Signup to post a comment