Dot Notation

Dot notation allows you to access specific fields or data nested within a variable. Dot notation is a general programming concept and it is also a useful tool in Xano. You can apply dot notation on any input/value line within the Function Stack or Response - whether that be within Functions or Filters. Watch the tutorial to understand important rules and concepts around dot notation in Xano.

Using dot notation

Dot notation must be used on an existing variable in Xano.

Let's use the variable car as an example. Below you can see that 'car' is data retrieved from a database table with a Get Record function. The response shows us the contents of the variable - all the fields and data.

Let's say we want to retrieve just the make of the car variable. For this we can use dot notation to do so.

**It's very important to make sure the data type, as signified on the top of the input/value line is var: any (this signifies we have a variable data type selected).**

Once the variable is selected, add a '.' after the variable name and type out the field name of the data you wish to retrieve. **Spelling must be an exact match**

If we return the new variable make of car we will return the value of car.make, which is "toyota."

Using dot notation with Lists (Arrays)

Using the same example from above, let's say we have a Query all records function that queries all records from the car database table and returns an array of 3 cars stored in the variable car. It will return a large payload that looks something like below:

[
   {
      "id":4,
      "created_at":1632268901955,
      "make":"honda",
      "model":"civic",
      "year":2002,
      "maintenance":[
         {
            "year":2004,
            "description":"New bumper"
         },
         {
            "year":2009,
            "description":"Radiator"
         }
      ]
   },
   {
      "id":1,
      "created_at":1632268899571,
      "make":"toyota",
      "model":"corolla",
      "year":1998,
      "maintenance":[
         {
            "year":2015,
            "description":"New enginge"
         },
         {
            "year":2008,
            "description":"Transmission"
         }
      ]
   },
   {
      "id":2,
      "created_at":1632268900442,
      "make":"jeep",
      "model":"wrangler",
      "year":2007,
      "maintenance":[
         {
            "year":2016,
            "description":"Suspension"
         }
      ]
   },
   {
      "id":3,
      "created_at":1632268901252,
      "make":"ford",
      "model":"4 runner",
      "year":2004,
      "maintenance":[
         {
            "year":2011,
            "description":"Windshield"
         },
         {
            "year":2013,
            "description":"Passenger door"
         }
      ]
   }
]

Now if we only wanted to return a list of car makes without all the extra bloat, traditionally you would have to do a for each loop function and store each car name in an array in its own variable. Luckily, using Xano's Dot Notation engine, you can easily get the makes of the cars.

We can create a variable and specify car.make which will return an array of just the car makes:

Now when you return the variable just_the_makes It will return an array that looks like this:

"`car.make`""="[
   "honda",
   "toyota",
   "jeep",
   "ford"
]

GET filter

The GET filter allows you to return the value of an object at a specified path. In other words, it's another way to use dot notation but with a filter.

You can think of the GET filter like replacing a . in dot notation. For example, to retrieve the make of a car instead of car.make - you could apply the GET filter to say car|GET|make

Why use the GET filter?

The GET filter has a unique advantage that can be very useful for certain use cases. It allows you to define a default value in case the specified path does not exist.

Use cases where this may come in handy would be when calling an external API or receiving a Webhook and the returned payload can differ. Possibly you are working with a field that is sometimes present and sometimes not. Defining a default value with the GET filter allows your function stack to continue to run and complete the logic you are performing. You can also use conditional logic based on a default value to perform certain logic if the specified field does not exist.

Using Xano Transform with the GET Filter

The GET filter also supports inline expressions for even more powerful data retrieval. See more here.

Proper Pathing

The path option is parsed using the Xano Expression syntax. In some rare cases, the path you are retrieving may resemble an expression, such as event[0]. If this is the case, simply wrap your path in [" and "] to ensure it behaves as expected.

Escape Sequence - Double Dot Notation

While quite rare, there are occasions when a . may be required in a path name. An example of this is likely to come from a 3rd party API that requires a . in a parameter name (i.e. parameter = name.first). Standard JSON and dot notation would treat "first" as a subpath of "name", however, in this rare example "name.first" is the entire name of the path.

To satisfy this use-case, Xano implements an escape sequence to tell the API that the . is required in the path name by implementing a double dot or .. where required.

Example

For this example, we will implement the path name "first.name" with the escape sequence.

The result is:

{
"first.name": "Michael"
}

Last updated