Extract a specific value from an Array in make.com

Learn how to extract specific values from nested arrays in Make.com using the map function and Array Aggregator. The presenter shows how to find matching IDs, pull the amount field, and handle cases where results nest arrays within arrays using direct indexing or an Iterator.
Chapters
Hi, now real quick, here's how you extract the value from a nested collection. Um, so based, based on your forum post, I basically replicated your, your input in a PostJSON. So we basically, we basically have something like this right here, right, where we have, um, like a few arrays, like here an array, a collection, but we want to get values from an array based on stuff in here, pretty much. Um, right, so first up, your first module, just to show you, if we just use, use your_input and just set a variable for whatever, doesn't really matter to be honest, and we run it, you can see how your_input creates several bundles. So it doesn't output as an array, it outputs as several bundles, separate bundles here. See, we don't want that because what you always want to do in Make.com is, uh, or generally in all of these automation platforms, is you want to batch, uh, batch all collections. So you want to work as little with bundles as possible and as much as arrays as possible. And if you change something or you do something, it's best to always work with arrays. Obviously that is a lot harder to do. Like, it is super easy building pretty much anything by iterating through each result and doing stuff with that and filtering and everything, but, um, that really wastes a ton of operations in the end. So it's always best to batch them pretty much and to turn them into an array or put them into an array or aggregate them into an array. So what we want to do, and I already have that here, we want to add an array aggregator to aggregate them into an array, right? So what we set up in the array aggregator is the source module is just your input. So whatever module produces, produces that output right here. And then you just want to aggregate all fields, right? And you save that. And if I just run that, you will see now we get as output just 1 because because we aggregated all of them into one array, right? So that's great. Now, as next module, you want to pretty much— just show you— you want to get the, uh, the values. So what's inside the values array for the collection where the ID equals to that right here, right? So what we're doing is we set a variable and we use the map function. Map function is great because we can get a specific value from a collection of an array where a specific other value is equal to something. So what that means is map has, um, 2 to 4 fields, right? And it outputs an array as well. So the first one is the actual array we want to work with. So in this case, you would input the array we just got from the array aggregator, and then the next ones you don't want to map but instead you want to, uh, actually write in here. So you want to use text. So we want to get the values field, which is an array where the ID is equal to that. So if we just real quick look at that, we want to get— and I know it's bundle 9 in this case— we want to get the values array, this one, where the ID is equal to that. So it would return the 9, right, the 9th bundle in this case, uh, or collection down here, right? Uh, so that's how that works. And what do we get? We get an amount bundle, uh, an amount array I mean. And in here we have, we have it. So it, it got, it got for us the correct one. The amount for this one is 500. We have the currency in here. And now just to demonstrate to you, if I just went in here to it's not this one, it's this one, right? If I just went in here and I added another collection inside that amounts array, so let's make that for $5 USD, and I save that and render it once more, you will see how we get as output an array with both of those, both collections, uh, so both amounts, right? So that's great. Now you can work with each, each of the ones in there. And what you can do for that, obviously now you can do whatever you want, right? You have extracted all of the amounts in there and you can, you can totally work with that now. Um, and for example, what you can do— by the way, real quick, one thing I just saw is that we get an array nested inside an array. That's obviously not really what we want. We don't want to have an array nested in another array. That just complicates things. So let me just check real quick live here, uh, what the solution to that would be. So usually you would— because I can also tell you why that is. Because the map function pretty much gives us the, um, it gives us an array back. It gives us a simple array back because what it expects is— usually what it expects to in the results is to find several fields that have the same identifier, and then it can put all of them into an array, right? Which in this case isn't the case. So let's, let's just try if that works. Uh, value dot— I think it's amount. I'm not 100% sure if that works. I do not— I actually do not think it works, but let me just check. Otherwise it's still not a problem. Yeah, it does not work. Um, values.1.amount. So that should technically, if I'm not mistaken, just get the first one. Oh yeah, yeah, there you can see that. Uh, so if, if you are totally fine with just getting the first one and you want to make life simple, you just do that, values.1.amount. So technically, if we put values.2.amount, we should get the second one inside the values. But if you want to get each of them inside values, yeah, Right, so if you want to get each of them inside values, uh, you would now just keep it as values, right? And now what you want to do is iterator, and we can iterate over— oh, that, that should work. Let me try with each of those Okay, yeah, here you go, here you go. That's how it works, that's how simple it is. So what you want to do is, uh, and let me tell you— oh no, not that again. There's some, some like weird bug with Make where it shows it in a weird format, and I'm not sure what causes that. So, but what you want to do is you basically want to, in this case, because we have an array inside an array, we actually want inside the amount array to just get the first result, because the first result is the actual array that contains everything. So you want to go in here and you want to open amount and then click on the one. So it should look like this, right? Because then it iterates through each of the items because it's an array inside an array. Um, and now as output we get as a separate bundle each of the items in there, right? So we get the €500 and the $4,500 which I just added, uh, and you can work with those. So you have them separate now. If you want to have them in an array, which is pretty cool because now you can do whatever you want with those— if you want to keep them in an array now, because now you have separate bundles, meaning it— whatever you do now after it will repeat for each of them. You can do with each of them. If instead you want them just within an array as well, then you would just select the main amount, and now it will basically just output 1. Right, so we run that once. Yeah, it just outputs one array, and inside that array you have your two collections, right? So that's, that's how simple it is. Uh, and now you can do whatever you want with it and work with the values in, in there. And as, as you've just seen, if you just want like the very first one, you don't even care about having several values in there, there's either always just one or you just always want to get the first one, you, you can just keep it much simpler. You just do values.1.amount, right? And then, um, you do that, you run it, and out you get— I think it's mapped wrong. No, there you go. And out you get just your value from the first one. And yep, that's how it works. I really hope that helped, and you have a good one. Bye!










