This article describes how to iterate over a JSON object (or how to use the Object - For Each card).
- Okta Workflows
There is a JSON object, most likely from an API call, that looks like this:
{ "file_type": "Locations", "file_content": { "Location 1": { "ipv4_allowlist": [ "128.10.10.01", "128.10.10.02" ], "description": "Location 1 gateway" }, "Loation 2": { "ipv4_allowlist": [ "128.10.10.03", "128.10.10.04" ], "description": "Location 2 gateway" }, "Location 3": { "ipv4_allowlist": [ "128.10.10.05", "128.10.10.06" ], "description": "Location 3 gateway" }, "Location 4": { "ipv4_allowlist": [ "128.10.10.07", "128.10.10.08", "128.10.10.09" ], "description": "Location 4 gateway" } }}
Go over this JSON and get only the IP addresses. To get the IP addresses, use the Object – For Each card. Look at the example flow below.
-
Using For Each to iterate over a JSON object.
This is the main flow:
On the screenshot above:
- Most likely, the JSON is taken from an API call. In this example, the JSON is created using JSON – Parse card. Note that the file_content (object) path is defined under the output path. This allows passing the file_content path to the next card.
- The file_content path is passed to the Object – For Each card. The card calls the Map_ForEach_helper flow. The card passes a key and a value to the helper flow. Looking at the JSON file, the key is Location 1 and its value.
-
Helper flow to iterate over a JSON object.
This is the helper flow:
In this helper flow:
- The Helper Flow card defines two inputs: Key (string) and Value (object).
- Using the Get Multiple card, ipv4_allowlist retrieves the IP addresses from the object.
-
Running the flows to get the IP addresses.
This screenshot shows how the helper flow works:
-
Updating the flow to retrieve each IP address.
The ipv4_allowlist field now holds the IP address that we want to retrieve. But it’s a list of IP addresses. Update the flow to get each individual IP address.
First, add another helper flow:
In this helper flow:
- An IP address is passed to this flow and then assigned to the IP Address field (using the Assign card) for display purposes.
In the first helper flow, from where a list of IP addresses will be collected, add a List – For Each card:
In this flow:
- When there is a list of IP addresses, this list is then passed to the For Each card, from where one can get each individual IP address.
Flow history retrieving one IP address:
-
Video.
Watch a short video about these flows.
