Friday Fact: Azure Logic Apps Supports Both Dot and Bracket Notations

  • Luis Rigueira
  • Mar 29, 2024
  • 3 min read

Azure Logic Apps provides a flexible and first‑class way to access data in JSON structures. Developers usually access this data through tokens after applying a JSON schema. Many also rely on bracket notation for direct access.

Behind the scenes, tokens use bracket notation to reference values. However, Logic Apps offers another option. There is an alternative convention that many developers overlook.

📝 One-Minute Brief

Learn how Azure Logic Apps supports both dot and bracket notations to access JSON properties, when to use each approach, and how choosing the right notation improves readability and flexibility.

Consider we receive the following JSON input in a Logic App through a When a HTTP Request is received trigger:

{
    "ID": {
        "name": "Luis",
        "lastName": "Rigueira",
        "age": 34
    }
}

The approach to accessing the name using the bracket notation would be using the expression:

triggerBody()?['ID']?['name']

In a Logic Apps context:

Logic App workflow

Many developers don’t realize that Logic Apps also supports dot notation, and they rarely use it. Based on the previous example, you can access the same field using dot notation like this:

triggerBody().ID.name

In a Logic Apps context:

Logic App workflow

As you can see, both methods return the same output.

Postman call

The dot notation feels more natural and readable, so why do we not use it more often?

Dot notation is notably more streamlined and mirrors the property access seen in programming languages like JavaScript, enhancing readability. Bracket notation, however, brings a level of versatility to the table.

While both notations are valid and can be used interchangeably in many cases, bracket notation has the upper hand when it comes to accessing properties with dynamic names or names that include special characters, which dot notation can’t handle.

Dot Notation: Known for its simplicity and readability, dot notation is straightforward. It allows you to access the properties of a JSON object directly by name. For instance, triggerBody().ID.name effortlessly fetches the name property from the trigger body of a Logic App that receives the previous input. This notation shines in its clarity, making code easier to read and understand at a glance.

Bracket Notation: Bracket notation, on the other hand, provides a level of flexibility unmatched by dot notation. It allows for the dynamic access of properties and the handling of property names that contain special characters or spaces.

Let’s take this JSON as an example:

{
  "user-info": {
    "first-name": "John",
    "last-name": "Doe"
  }
}

Here, the bracket notation, (triggerBody()[‘user-info’][‘first-name’]), accesses properties that would be inaccessible with dot notation due to the presence of hyphens. This method is indispensable when dealing with dynamic property names or JSON objects with complex structures.

And, in case you were wondering, yes, you can combine both methods together!

triggerBody().ID['name']
Logic App workflow

In conclusion, while Azure Logic Apps support both dot and bracket notations for accessing JSON properties, each notation has its strengths and best use cases.

Ultimately, the choice between dot and bracket notation depends on the specific requirements of your Logic App and the nature of the JSON data you’re working with. By understanding the strengths of each notation, you can leverage them effectively to build robust and adaptable Logic Apps tailored to your needs.

To lazy to read? We’ve got you covered! Check out our video version of this content!

Hope you find this helpful! If you enjoyed the content or found it useful and wish to support our efforts to create more, you can contribute towards purchasing a Star Wars Lego for my son!

Author: Luis Rigueira

Luis Rigueira is a Enterprise Integration Consultant at DevScope

Leave a Reply

Your email address will not be published. Required fields are marked *

The Ultimate Cloud
Management Platform for Azure

Supercharge your Azure Cost Saving

Learn More
Turbo360 Widget

Back to Top