How to use JSON with unknown keys

Hello!

I am retrieving data from an API that has this structure:

"answers": {
    "number": 16,
    "textField": "Safety talk",
    "number1": 4,
    "textField1": "Incident report",
    "number2": 4,
    "textField2": "Safety policy"
    ...
}

There can be an unlimited and unknown number of properties. I need to get the values of all the textField* properties (however many there are) and pass them as a JSON formatted parameter to a subsequent API call, eg

/documents?filter={ "where": { "or": [{"template": "Safety talk"}, {"template": "Incident report"}, {"template": "Safety policy"}]}}

I’m new to Make. After a lot of searching on the forums and watching videos about iterators, aggregators, and map functions I still don’t really have an idea as to how to tackle this.

Thank you for any assistance!

Welcome to the Make community!

1.

You can use a Text Parser “Match Pattern” module with this Pattern (regular expression):

"textField\d*": "(?<value>.+)"[,\s]

Proof https://regex101.com/r/jcicw2/1

Important Info

  • :warning: Global match must be set to YES!

For more information, see the Text Parser page in the Make Help Center:

Match Pattern
The Match pattern module enables you to find and extract string elements matching a search pattern from a given text. The search pattern is a regular expression, which is a sequence of characters in which each character is either a metacharacter, having a special meaning, or a regular character that has a literal meaning.

2.

Then, you can use a Text Aggregator to build your JSON formatted parameter.

Combining Bundles Using Aggregators

Every result (item/record) from trigger/iterator/list/search/match modules will output a bundle. This can result in multiple bundles, which then trigger multiple operations in future modules (one operation per bundle). To “combine” multiple bundles into a single variable, you’ll need to use an aggregator of some sort.

Aggregators are modules that accumulate multiple bundles into one single bundle. An example of a commonly-used aggregator module is the Array aggregator module. The next popular aggregator is the Text Aggregator which is very flexible and can apply to many use-cases like building of JSON, CSV, HTML.

You can find out more about the other types of aggregator modules here:

Question: Which type of aggregator do you think you’ll need?

Example

Here is an example of how your scenario could look:
Screenshot_2025-04-26_140408

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

For more information, see the “Mapping with arrays” link below. You should also do the Make Academy, which also covers the use of Iterators & Aggregators.

Getting Started

Help Centre Basics

Articles & Videos

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.