<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-M74D8PB" height="0" width="0" style="display:none;visibility:hidden">
Loading
Skip to NavigationSkip to Main Content
How to Iterate Over a JSON Object (or How to Use the Object – For Each Card)
Workflows
Okta Classic Engine
Okta Identity Engine
Overview

This article describes how to iterate over a JSON object (or how to use the Object - For Each card).

Applies To
  • Okta Workflows
Solution

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. 

  1. Using For Each to iterate over a JSON object.

This is the main flow: 
workflows  

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. 
  1. Helper flow to iterate over a JSON object.

This is the helper flow: 

workflows

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.
  1. Running the flows to get the IP addresses.

This screenshot shows how the helper flow works: 

workflows

  1. 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:

workflows

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: 

workflows

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: 

workflows

  1. Video.

Watch a short video about these flows. 

Related References

Loading
How to Iterate Over a JSON Object (or How to Use the Object – For Each Card)