Software Development

Workflows Tips #42: Creating a JSON Object, Searching a JSON Object, and Using the List-Reduce Card

Welcome to another Okta Workflows Tips post. Read all previous tips.

In this post:

  • Creating a JSON object
  • Searching a JSON object
  • Reducing a list to a single value (how to use the List-Reduce card)

Creating a JSON object

Here is how to create a JSON object using the Object-Construct card:

Creating a JSON object

Note that field names were renamed, and the result is this JSON object:

Testing the Object-Construct card

Although it is possible to use the Text-Compose card to create a JSON object, it is recommended to use the Object-Construct card. Using the Construct card is less error-prone.

Searching a JSON object

Thanks to Bryan Barrows (Workflows Product Specialist at Okta) for sharing this flow.

This example from Bryan shows how to search a JSON object.

Searching a JSON object

You can download the JSON file used in this example.

The goal is to find the Battery Condition value.

This is how the flow works:

  1. The first card, the JSON-Parse card, creates the JSON object from a string. In your situation, you might be getting the JSON from another card such as a search or API call
  2. The List-Filter card finds the objects where the name is set to Battery Condition
  3. The List-Collapse card transforms a list of objects into a single object
  4. And finally, the Object-Get Multiple card retrieves the value property that holds that battery condition
Searching a JSON object result

Reducing a list to a single value (how to use the List-Reduce card)

This blog post has three examples of how to use the List-Reduce card.

Reducing a list to a single value

The examples are:

  • A list of numbers – sum all the numbers
  • A list of numbers – find the largest (or smallest) number
  • A list of messages (text) – create a single message containing all the messages from a list

Read the blog post.

Published on Java Code Geeks with permission by Max Katz , partner at our JCG program. See the original article here: Workflows Tips #42: Creating a JSON Object, Searching a JSON Object, and Using the List-Reduce Card

Opinions expressed by Java Code Geeks contributors are their own.

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button