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:
Note that field names were renamed, and the result is this JSON object:
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.
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:
- 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
- The List-Filter card finds the objects where the name is set to Battery Condition
- The List-Collapse card transforms a list of objects into a single object
- And finally, the Object-Get Multiple card retrieves the value property that holds that battery condition
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.
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. |