Okta Workflows how-to guides are questions and answers from weekly community office hours, MacAdmins Workflows Slack channel, and other places.
Read all the other how-to guides ⤵️
All Okta Workflows How-To Guides
Okta Workflows Staff for Okta Workflows ・ Aug 23 '22
On to the question.
How to read a JSON path with dot-notation?
As you build workflow automations it is likely you will need to read values from a JSON object. For example, from an external API endpoint that returns data as JSON. Workflows has two cards to help read (retrieve) values from JSON:
- Object – Get
- Object – Get Mutliple
We 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
}
}
}
The dot-notation is a path that corresponds to an item in JSON.
For example, a path of product
will return:
ice cream
Using Object – Get card to read JSON
In Workflows, use the Object – Get to read a JSON path:
Testing this card:
Let’s look at more examples.
Using the path ingredients.ingredient.0
will result in:
{ "id": 100, "type": "chocolate"}
this is how it looks when testing using Object – Get card:
One thing to keep in mind is that the output type needs to match the JSON type. If the path you entered retrieves a plain text then the type should be Text. If the path retrieves an object then the type should be set to Object (or you will get incorrect results).
Using the above example, setting the output type to Text will result in this:
Setting correct output type:
This example shows how access an array with ingredients.ingredient.1.type
:
Note that the output type is set to Text as the output is a string.
One more example using the path of shop.inventory
will return
{
"instock": 100,
"ordered": 50
}
Note that the output type is set to Object as the output is an object.
Using Object – Get Multiple to read JSON
Object – Get outputs a single JSON path, Object – Get Multiple works the same and can output multiple paths. You enter any number of paths you need as output:
Note the the output type is set on the path itself when using Object – Get Multiple card.
The JSONPath Online Evaluator is an online tool where you can test your dot-notation paths.
If you need to validate (and format) a JSON sample, use the JSON Lint tool.
Two resources to help you learn more:
📘 Try this step-by-step getting started tutorial: Build Your First Automation With Okta Workflows: Notify When User Is Suspended.
📺 Short how-to Workflows videos to help you become a better automation builder.
Top comments (0)