In this post, we'll dive into the latest updates to Xano's set filter, allowing you to manipulate and transform your data using inline expressions. This powerful feature streamlines your workflow, eliminating the need for stacked loops and conditionals, ultimately saving you time and effort. Let's get started!
Before we begin, ensure you're familiar with Xano's expression data type and the updates to the git filter. These concepts lay the foundation for the new set filter functionality. If you're not familiar with them, check out our previous videos on these topics.
Let's kick things off with a simple example: capitalizing product names. Traditionally, you'd create an empty variable, loop through the products, apply a conditional to check the price, rating, and stock, and then use the toUpper filter to capitalize the product name. With the set filter, you can achieve the same result more efficiently. Here's how:
${products.response|get:results|?price>700&rating>4.5&stock>0|set:name=$$name|uppercase}
In this expression, we're using the get filter to retrieve products from the response key, and then applying conditions to filter by price, rating, and stock. The set:name=$$name|uppercase part capitalizes the product name using the uppercase filter.
You can chain multiple filters to the same expression. For example, to lowercase the capitalized product names:
${products.response|get:results|?price>700&rating>4.5&stock>0|set:name=$$name|uppercase|lowercase}
Text concatenation is also possible within the set filter:
${products.response|get:results|?price>700&rating>4.5&stock>0|set:name='hello'~$$name|uppercase}
This expression adds "hello" before each product name.
In the next example, we'll adjust both the product name and price simultaneously. Here's how you'd typically handle this using loops and conditionals:
// Loop through products
// Check price, rating, and stock conditions
// Update product name using toUpper filter
// Check if stock is greater than 50
// If true, multiply price by 0.9
// Else, multiply price by 1.3
// Update price with dollar sign, concat filter, and numberFormat filter
With the set filter, you can accomplish the same task in a single line:
${products.response|get:results|?price>700&rating>4.5&stock>0|set:name=$$name|uppercase,price='$'~$$price*($1.stock>50?0.9:1.3)|numberFormat:2,'.',',' }
In this expression, we're using anchored selection ($1.stock>50) to reference the stock value outside of the price value we're currently working with. The ? denotes an if-then statement, checking if the stock is greater than 50. If true, we multiply the price by 0.9; otherwise, we multiply it by 1.3. Finally, we apply the numberFormat filter to format the price with a dollar sign, two decimal places, a period as the decimal separator, and a comma as the thousands separator.
The power of inline expressions in Xano's set filter is practically limitless. You can build faster, more efficiently, and socialize your work with the Xano community by sharing and reusing expressions.
To explore the full capabilities of these updates, be sure to check out our documentation. If you have any questions, feel free to leave a comment below, reach out on the Xano community at community.xano.com, or contact us via the support chat inside Xano.
Start unleashing the power of inline expressions in Xano's set filter today and take your productivity to new heights!
Join 100,000+ people already building with Xano.
Start today and scale to millions.
Start building for free