VOOZH about

URL: https://www.javacodegeeks.com/2022/10/workflows-tips-42-creating-a-json-object-searching-a-json-object-and-using-the-list-reduce-card.html

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


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:

👁 Image
Creating a JSON object

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

👁 Image
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.

👁 Image
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
👁 Image
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.

👁 Image
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.

Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy

Thank you!

We will contact you soon.

👁 Photo of Max Katz
Max Katz
October 25th, 2022Last Updated: October 25th, 2022
0 170 1 minute read
Back to top button
Close
wpDiscuz