Filtering on array of objects

Hi,

I use HTTP module, which returns array of objects (data[]). Each item has ID and EMAIL (data = [{ID: 123, EMAIL: “xyz”},{ID: 345, EMAIL: “xyz”}])

I want to filter them, only to include every object, which has ID 123 (there may be multiple of them).

Current approach

  1. HTTP – response is automatically converted to an array of objects JSON (aka → data[] and each item has ID and EMAIL)
  2. Set filter → data[].ID equals 457
  3. After running it will return 0 results (does not return objects with ID 123) → ID 123 exists!

Possible fix → Use ITERATOR

  1. HTTP
  2. ITERATOR
  3. Set filter → ITERATOR.ID equals 123
  4. Filtering works

Is there a way how to handle this array without iterator?

@amparo

In this case, yes:

map(data;EMAIL;ID;123)

This will return a primitive array of the emails where the ID is “123”.


Jim - The Monday Man (YouTube Channel)
Watch Our Latest Video: The monday ITEM ID column - What most people don’t know.
Contact me directly here: Contact – The Monday Man

2 Likes

Hi, thank you!

Is there also a way to use smarter filter?

Let’s assume, there is EMAIL, ID, DATE in each object in the array. (And I need only EMAILs as primitive array)

Right now I have in filter (after Iterator) {{parseDate(1.DATE; "YYYY-MM-DD")}} less than {{addDays(setDate(now; 1); -30)}}

@amparo

To filter dates, use “real” dates (not strings, as you are already doing) AND Datetime comparators:

{{parseDate(1.DATE; "YYYY-MM-DD")}} Earlier than {{addDays(setDate(now; 1); -30)}}


Jim - The Monday Man (YouTube Channel)
Watch Our Latest Video: The ITEM ID column - What most people don’t know.
Contact me directly here: Contact – The Monday Man

2 Likes

@JimTheMondayMan do you know if there is a way to just filter the original complex array. I mean, when I don’t want to extract a primitive array from it. If I use the example above, then instead of:

map(data;EMAIL;ID;123)

I would like to return the original data array, e.g. something like this (it doesn’t work obviously):

map(data;data;EMAIL.ID;123)
1 Like

Figured it out. What I failed to realise was that one can set a filter on a connection!

1 Like

Hey - did you manage to add a filter to return the original data array as per your point above? I’ve been trying but can’t seem to get a filter to work for this!

Thanks