How to count occurrences of a specific value in a JSON array without using iterators?

Hi, I need to count the occurrences of a specific Status (pending, approved, disapproved) in a JSON response from Google Merchant Center within my Make.com scenario.
I want to avoid using iterators because I deal with a large number of products, and using iterators would result in a huge number of operations and high costs.

The Api response looks like this:

{
“resources”: [
{
“productId”: “12345”,
“destinationStatuses”: [
{
“destination”: “Shopping”,
“status”: “pending”
},
{
“destination”: “SurfacesAcrossGoogle”,
“status”: “approved”
}
]
},
{
“productId”: “67890”,
“destinationStatuses”: [
{
“destination”: “Shopping”,
“status”: “pending”
},
{
“destination”: “SurfacesAcrossGoogle”,
“status”: “pending”
}
]
}
]
}

The goal is to count how many times "pending", "approved", and "disapproved" appear in all destinationStatuses[] across all products without using iterators.

What I need help with:

  1. How can I correctly extract all destinationStatuses[] across all products in the JSON without using iterators?
  2. How can I correctly count the occurrences of a specific value (status = "pending") within this array using Make formulas?
  3. Is there a better way to achieve this?

Any help, advice, or a correctly written formula would be highly appreciated! :rocket: Thanks in advance!

Welcome to the Make community!

Yes, that is possible. You’ll need a minimum of one module:

Output:

This is just an example. Your final solution may or may not look like this depending on your requirements.

Hope this helps! Let me know if there are any further questions or issues.

@samliew

P.S.: Investing some effort into the Make Academy will save you lots of time and frustration using Make.

Module Export - quick import into your scenario

You can copy and paste this module export into your scenario. This will import the modules (with fields/settings/filters) shown in my screenshots above.

  1. Move your mouse over the line of code below. Copy the JSON by clicking the copy button on the right of the code, which looks like this:

  2. Enter your scenario editor. Press ESC to close any dialogs. Press CTRLV (paste keyboard shortcut for Windows) to paste directly in the editor.

  3. Click on each imported module and re-save it for validation. There may be some errors prompting you to remap some variables and connections.

JSON module export — paste this directly in your scenario

{"subflows":[{"flow":[{"id":334,"module":"json:ParseJSON","version":1,"parameters":{"type":""},"mapper":{"json":"{\"resources\":[{\"productId\":\"12345\",\"destinationStatuses\":[{\"destination\":\"Shopping\",\"status\":\"pending\"},{\"destination\":\"SurfacesAcrossGoogle\",\"status\":\"approved\"}]},{\"productId\":\"67890\",\"destinationStatuses\":[{\"destination\":\"Shopping\",\"status\":\"pending\"},{\"destination\":\"SurfacesAcrossGoogle\",\"status\":\"pending\"}]}]}"},"metadata":{"designer":{"x":1116,"y":-772},"parameters":[{"name":"type","type":"udt","label":"Data structure"}]}},{"id":335,"module":"util:SetVariables","version":1,"parameters":{},"mapper":{"variables":[{"name":"pending","value":"{{length(map(flatten(map(334.resources; \"destinationStatuses\")); \"status\"; \"status\"; \"pending\"))}}"},{"name":"approved","value":"{{length(map(flatten(map(334.resources; \"destinationStatuses\")); \"status\"; \"status\"; \"approved\"))}}"},{"name":"disapproved","value":"{{length(map(flatten(map(334.resources; \"destinationStatuses\")); \"status\"; \"status\"; \"disapproved\"))}}"}],"scope":"roundtrip"},"metadata":{"designer":{"x":1416,"y":-772,"name":"Tally Statuses"}}}]}],"metadata":{"version":1}}

Note: Did you know you can reduce the size of blueprints and module export code like the above, using the Make Blueprint Scrubber?


A popular tool that I’m using is Dumpling AI.

DumplingAI also does so much, see:

In summary, Dumpling AI is able to replace several other paid services combined that cost more than itself, making it a noteworthy choice as the “multi-tool” of AI services.

Examples of How to use Dumpling AI

For more information, see these Dumpling AI tutorials below, grouped by category:

YouTube & Videos

Image Generation

AI Agents & RAGs

Searching & Scraping

Other Data Extraction

Business & Social

Dumpling AI Tutorials

How to Use

For more information on how to set this up, refer to these forum threads:

Hope this helps! Let me know if there are any further questions or issues.

@samliew

P.S.: Investing some effort into the Make Academy will save you lots of time and frustration using Make.

1 Like

Thank you very much for your reply. However, I need to filter / count the statuses in destinationStatuses: pending, approved, disapproved only for “destination”: “Shopping”, ideally with the structure set to strict=false.

This workflow will work for multiple clients, and I don’t want to hardcode it to specific products because they will be variable. The products could be 10 or 1000, depending on the client. I only need to count how many products have pending, approved, or disapproved statuses.

Could you please help me make the code more universal? Thank you so much!

No problem, really glad I could help!

1. If anyone has a new question in the future, please start a new thread. This makes it easier for others with the same problem to search for the answers to specific questions, and you are more likely to receive help since newer questions are monitored closely.

2. The Make Community guidelines encourages users to try to mark helpful replies as solutions to help keep the Community organized.

This marks the topic as solved, so that:

  • others can save time when catching up with the latest activity here, and
  • allows others to quickly jump to the solution if they come across the same problem

To do this, simply click the checkbox at the bottom of the post that answers your question:
Screenshot_2023-10-04_161049

3. Don’t forget to like and bookmark this topic so you can get back to it easily in future!

Hope this helps! Let me know if there are any further questions or issues.

@samliew

P.S.: Investing some effort into the Make Academy will save you lots of time and frustration using Make.

Hello,
unfortunately, the problem hasnt be solved.

As i said:

Could you please help me to solve my problem? Thank you