Hey there! In this blog post, we'll dive into the exciting new "Create Object from Entries" filter in Xano. This handy feature allows you to take a set of data, filter through it, and return a new object with only the desired data. It's perfect for situations where you need to remove blank values or unwanted data from an object, like when working with third-party API responses.
Let's start with an example JSON object that we'll be working with:
{
"A": 1,
"B": 2,
"C": "",
"D": 3,
"E": "",
"F": 5,
"G": 6
}
As you can see, this object has several key-value pairs, but two of them ("C" and "E") are empty.
The first step is to separate the keys and values of the object into separate arrays. We'll use the entries filter for this:
entries
This filter gets the property entries of an object or array as a numerically indexed array of key-value pairs. After applying this filter, our data will look like this:
[
["A", 1],
["B", 2],
["C", ""],
["D", 3],
["E", ""],
["F", 5],
["G", 6]
]
Next, we'll use the filter_empty filter to remove the key-value pairs with empty values:
filter_empty(value)
Here, we specify the value path to indicate that we want to filter out empty values from the value part of the key-value pairs.
After applying this filter, our data will look like this:
[
["A", 1],
["B", 2],
["D", 3],
["F", 5],
["G", 6]
]
Finally, we'll use the brand new "Create Object from Entries" filter to consolidate the filtered key-value pairs back into a single object:
create_object_from_entries
This filter creates an object based on an array of key-value pairs, giving us our final result:
{
"A": 1,
"B": 2,
"D": 3,
"F": 5,
"G": 6
}
And just like that, we've effortlessly filtered out the empty values from our original object!
The "Create Object from Entries" filter in Xano provides a seamless way to clean up your data and remove unwanted values from objects. Whether you're working with third-party API responses or any other data source, this filter can save you time and hassle by automating the process of data cleaning.
Give it a try and let us know how it works for you! And don't forget to join the Xano community for more tips, tricks, and discussions around no-code development.
Join 100,000+ people already building with Xano.
Start today and scale to millions.
Start building for free