Okta Workflows Tips #92: How to Turn a List of Key-Value Pairs Into an Object

Short and handy Okta Workflows tips and tricks. Read the full series.

APIs often return key-value data as a list of {name, value} objects instead of a clean object you can reference by key. This tip shows how to turn a list of key-value pairs into an object.

Workflows flow with five connected steps: Text Compose node with JSON key-value pair input, JSON Parse node, two List Pluck nodes extracting name/keys and value/values fields, and an Object Zip node combining keys and values into an object.
Turn a list of key-value pairs into an object.

How the flow works

  1. The Text-Compose card creates a sample JSON string from the following input:
JSON
[
{ "name": "department", "value": "Engineering" },
{ "name": "costCenter", "value": "CC-4521" },
{ "name": "employeeId", "value": "E10293" }
]
  1. The JSON-Parse card converts that string into a JSON array of objects.
  2. The first List-Pluck card extracts the name value from each object, producing a keys list: ["department", "costCenter", "employeeId"]
  3. The second List-Pluck card extracts the value from each object, producing a values list: ["Engineering", "CC-4521", "E10293"]
  4. The Object-Zip takes the keys list and the values list and pairs them up by position into a single object.
Workflows execution result showing five nodes — Text Compose, JSON Parse, two List Pluck nodes (keys and values), and Object Zip — with sample output: {"department":"Engineering","costCenter":"CC-4521","employeeId":"E10293"}
Turn a list of key-value pairs into an object execution.

The final JSON object looks like this:

JSON
{
"department": "Engineering",
"costCenter": "CC-4521",
"employeeId": "E10293"
}

Okta Workflows resources

Leave a Reply

Discover more from Max Katz

Subscribe now to keep reading and get access to the full archive.

Continue reading