Okta Workflows How-To: Read a JSON path with dot-notation

About the Author

Max Katz

Staff Developer Advocate, Okta Workflows

Max Katz is a Staff Developer Advocate for Okta Workflows. Max loves the no-code automation space and creating educational content. Before Okta, Max led the North America Developer Advocacy team at IBM. Before IBM, Max led developer advocacy for a cloud-based mobile app platform, Appery, helping it grow from zero to over 400,000 developers. Max regularly writes on his http://maxkatz.net blog. 

28 October 2022 Time to read: ~

A person is seated at a desk working on a computer in a modern office environment

Okta Workflows is a no-code platform for automating identity processes. The Workflows team holds weekly office hours where they answer builder questions.

This blog post is based on a question asked during office hours: How to read a JSON path with dot-notation in Workflows? 

Getting started

As you build Workflows automation, you will likely need to read values from a JSON object. For example, from an external API endpoint that returns data as JSON. Workflows have two cards to help read (retrieve) values from JSON:

  • Object – Get
  • Object – Get Multiple

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 the Object – Get card to read JSON

In Workflows, use the Object – Get to read a JSON path: 

Okta Workflows Object Get card displaying an input object with product and ingredients JSON, a path set to product, and an empty output field. Using the Get card for reading JSON path data

Testing this card:

Test "Get" modal displaying an input JSON object, path notation set to product, and evaluated output string "ice cream". Testing the Get card

Let’s look at more examples. 

Using the path ingredients.ingredient.0 will result in:

{
  "id": 100,
  "type": "chocolate"
}

Result when testing using the Object – Get card: 

Interface for testing a JSON path with dot notation, showing input JSON, path ingredients.ingredient.0, and output JSON. Using dot-notation in path

One thing to remember is that the output type needs to match the JSON type. If the path you entered retrieves plain text, 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: 

Test "Get" interface showing a JSON input object, path notation ingredients.ingredient.0, and output displaying [object Object]. Testing the Get card with an incorrect output type

Setting correct output type: 

Okta Workflows Object Get card configured with path ingredients.ingredient.0 and an orange arrow pointing to the output field labeled "Enter key name here". Testing the Get card with a correct output type

This example shows how to access an array with ingredients.ingredient.1.type:

Test "Get" modal displaying an array with chocolate and vanilla objects, path ingredients.ingredient.1.type, and output value "vanilla". Accessing array using a dot-notation path

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
}
Test "Get" modal displaying an input object with shop inventory JSON, path shop.inventory, and output JSON showing instock and ordered counts. Testing the Get card to access a JSON object

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. The Object – Get Multiple card works similarly and can output multiple paths. You enter any number of paths you need as output:

Okta Workflows Object Get Multiple card showing JSON input data, multiple path inputs including product and shop.inventory, and an orange arrow pointing to a selected path field. Using the Get Multiple card

Note that the output type is set on the path when using the Object – Get Multiple card. 

Test "Get Multiple" modal displaying input JSON and corresponding outputs for paths product, ingredients.ingredient.0, ingredients.ingredient.1.type, and shop.inventory. Testing the Get Multiple card

The JSONPath Online Evaluator is an online tool where you can test your dot-notation paths. 

JSONPath Online Evaluator web interface showing input JSON, JSONPath shop.inventory, and evaluated results displaying instock and ordered counts. JSONPath online evaluator tool

If you need to validate (and format) a JSON sample, use the JSON Lint tool.

Get your Workflows questions answered

Do you have a question about Okta Workflows? Not sure how to build a flow? Join the weekly community office hours to get help. 

About the Author

Max Katz

Staff Developer Advocate, Okta Workflows

Max Katz is a Staff Developer Advocate for Okta Workflows. Max loves the no-code automation space and creating educational content. Before Okta, Max led the North America Developer Advocacy team at IBM. Before IBM, Max led developer advocacy for a cloud-based mobile app platform, Appery, helping it grow from zero to over 400,000 developers. Max regularly writes on his http://maxkatz.net blog. 

Continue your Identity journey