<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 Extract Key-Value Pairs from a JSON Payload with Multiple Objects in Workflows
Workflows
Okta Classic Engine
Okta Identity Engine
Overview

This article is a guide for extracting key-pair values from a JSON payload with multiple objects in Workflows. 

Applies To
  • Workflows
  • Extract key-pair values
Solution
  1. Setting up the JSON file.
In this guide, the following JSON should be used:
{
  "sheets": [
    {
      "properties": {
        "sheetId": 0,
        "title": "Sheet1",
        "index": 0,
        "sheetType": "GRID",
        "gridProperties": {
          "rowCount": 1000,
          "columnCount": 26
        }
      }
    },
    {
      "properties": {
        "sheetId": 317732887,
        "title": "Sheet2",
        "index": 1,
        "sheetType": "GRID",
        "gridProperties": {
          "rowCount": 1000,
          "columnCount": 26
        }
      }
    },
    {
      "properties": {
        "sheetId": 2125125274,
        "title": "Sheet3",
        "index": 2,
        "sheetType": "GRID",
        "gridProperties": {
          "rowCount": 1000,
          "columnCount": 26
        }
      }
    },
    {
      "properties": {
        "sheetId": 144976084,
        "title": "Sheet4",
        "index": 3,
        "sheetType": "GRID",
        "gridProperties": {
          "rowCount": 1000,
          "columnCount": 26
        }
      }
    },
    {
      "properties": {
        "sheetId": 1179906118,
        "title": "Sheet5",
        "index": 4,
        "sheetType": "GRID",
        "gridProperties": {
          "rowCount": 1000,
          "columnCount": 26
        }
      }
    },
    {
      "properties": {
        "sheetId": 1615383701,
        "title": "Sheet6",
        "index": 5,
        "sheetType": "GRID",
        "gridProperties": {
          "rowCount": 1000,
          "columnCount": 26
        }
      }
    },
    {
      "properties": {
        "sheetId": 561243345,
        "title": "Sheet7",
        "index": 6,
        "sheetType": "GRID",
        "gridProperties": {
          "rowCount": 1000,
          "columnCount": 26
        }
      }
    }
  ]
}

  1. This JSON can be obtained from an API call. Use the Mock API service to create an endpoint that returns the above JSON for testing.

Click on this link for an example of an API endpoint.

  1. If API use is not an option, the Compose and Parse cards can be used to create a list of JSON objects shown in the screenshot below. Using the Compose and Parse cards to create a list of JSON objects.

Workflows

 

  1. Since we are working with a list, the solution has two flows:

 

  1. A main flow to get a list of objects (JSON file).
This is the main flow, to get the JSON data
Workflows

In this flow:

  1. The API Connector – Get card calls the API endpoint to get the JSON data.
  • In the cards Response section, the path sheets is added to the Body field. This allows direct passing the sheets field to the next card.
  • The sheets field is a JSON array, and its type is a list of objects.
Workflows
  1. The sheets field (JSON array) is passed to the List – For Each card.
  • The Get Multiple Keys_Helper helper flow is called for each item in the list (passed in the With the following values section).
  1. A helper flow that processes each item in a list and retrieves the key-pair value(s).

This is the helper flow:

Workflows   

 

The first card, the Helper Flow, receives each item (JSON object) that looks like this:

{
  "properties": {
    "sheetId": 561243345,
    "title": "Sheet7",
    "index": 6,
    "sheetType": "GRID",
    "gridProperties": {
      "rowCount": 1000,
      "columnCount": 26
    }
  }
}
  1. Using the Get Multiple card.

Next, specify the key for retrieving the value from the JSON object using the Get Multiple card. Use the dot notation for nested objects.

Workflows

The keys and their types specified on the card are:

  • properties (type Object)
  • properties.title (type Text)
  • properties.gridProperties (type Object)
  • properties.gridProperties.rowCount (type Text)

Output from the helper flow run:

Workflows   

 

The properties JSON key is used in every get. The properties key on Helper Flow card can be defined, without the need to use the name in the Get Multiple card.

The updated helper flow with the properties key set:

Workflows  
 

In the screenshot above, the properties key (type Object) is set on the Record field on the Helper Flow card. This allows passing the properties key value to subsequent cards.

The keys and their types specified on the card are:

  • properties.title (type Text)
  • properties.gridProperties (type Object)
  • properties.gridProperties.rowCount (type Text)

Related References

Loading
How to Extract Key-Value Pairs from a JSON Payload with Multiple Objects in Workflows