Updated: May 15, 2024
In this guide:
Okta Workflows guides
Okta Workflows guides are questions and answers from the community office hours, the #okta-workflows channel on MacAdmins Slack, and other places. Read all the other guides.
How to get data from a JSON object in Okta Workflows?
This guide will teach you how to extract data from a JSON object in Workflows.
Extract data from a JSON object
Building workflows requires reading values from a JSON object, such as a connector that returns JSON data or an external API endpoint that returns JSON data.
Okta Workflows has two cards to get values from JSON:
- Object – Get card.
- Object – Get Multiple card.
This guide will use the following JSON to show how the cards work:
{
"product": "ice cream",
"ingredients": {
"ingredient": [{
"id": 100,
"type": "chocolate"
},
{
"id": 200,
"type": "vanilla"
},
{
"id": 300,
"type": "caramel"
}
]
},
"shop": {
"inventory": {
"instock": 100,
"ordered": 50
}
}
}
Use the Object – Get card
Extract a simple value
Use the Object – Get card to read a JSON value:
Testing this card:
Extract an object
To extract the following object:
{
"id": 100,
"type": "chocolate"
}
Use the ingredients.ingredient.0 path (also called a key):
To extract the following object:
{
"instock": 100,
"ordered": 50
}
Use the shop.inventory path:
Extract data from a list
The following example shows how to get a list item with the ingredients.ingredient.1.type path:
Set output type
When you get a JSON value, set the correct value output type.
Retrieving value | Set output type to |
---|---|
Text | Text |
Number | Number |
Object | Object |
List | Object + List |
The following shows four different value types:
Using the Object – Get Multiple card
The Object – Get card outputs a single JSON path. The Object – Get Multiple card works similarly and outputs multiple values.
Enter multiple paths (or keys) to get values:
The output type is set on the path when using the Object – Get Multiple card.
Testing the card:
Add keys to a JSON object
You learned how to read JSON values using the Get and Get Multiple cards.
The User Sign In Attempt event has the Event Details JSON object. To get its values, you can use the Get Multiple card:
The Event Details JSON object has keys/objects the card is not exposing.
You can set up (expose) the keys inside the JSON object. Then, you can connect the values directly to another card without using the Get or Get Multiple card.
In the screenshot above, the Assign and Get Multiple cards produce the same result.
JSON utility tools
Several tools to help you work with JSON:
- Use JSON Lint to validate and format a JSON sample.
- Use JSONPath Online Evaluator to extract values from a JSON sample.
- JSONPath and Okta Workflows use different JSON parsers on the back end. Not all examples will work identically.
Okta Workflows resources
π« Get help from Workflows specialists during weekly community office hours.
πΊ Learn from Workflows videos.
π Get help from support: discuss a Workflows topic or ask a question.
ππ»ββοΈ Get help from the community: join the #okta-workflows channel on MacAdmins Slack.
Leave a comment