DEV Community

Max Katz for Okta Workflows

Posted on • Originally published at maxkatz.net on

How to Read a JSON Path With Dot-Notation in Workflows

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 ⤵️

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
      }
   }
}
Enter fullscreen mode Exit fullscreen mode

The dot-notation is a path that corresponds to an item in JSON.

For example, a path of product will return:

ice cream
Enter fullscreen mode Exit fullscreen mode

Using Object – Get card to read JSON

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

Get card for reading JSON path data

Get card for reading JSON path data

Testing this card:

Testing Get card

Testing Get card

Let’s look at more examples.

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

{ "id": 100, "type": "chocolate"}
Enter fullscreen mode Exit fullscreen mode

this is how it looks when testing using Object – Get card:

Using dot-notation in path

Using dot-notation in path

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:

Testing Get card with incorrect output type

Testing Get card with incorrect output type

Setting correct output type:

Testing Get card with correct output type

Testing Get card with correct output type

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

Accessing array using dot-notation path

Accessing array using 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
}
Enter fullscreen mode Exit fullscreen mode

Testing Get card to access a JSON object

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

Using Get Multiple card

Using Get Multiple card

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

Testing Get Multiple card

Testing Get Multiple card

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

JSONPath online evaluator tool

JSONPath online evaluator tool

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.

Latest comments (0)