Comment on page
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.
Dot notation must be used on an existing variable in Xano.
Let's use the variable
caras 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.
The variable car being returned in our response.
Let's say we want to retrieve just the
carvariable. 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**
In this new variable, we are using dot notation on the 'car' variable to retrieve the 'make' of the car by writing 'car.make'
If we return the new variable
make of carwe will return the value of
car.make, which is "toyota."
'car.make' = toyota
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.makewhich will return an array of just the car makes:
`car.make` = ["honda","toyota","jeep","ford"]
Now when you return the variable
just_the_makesIt will return an array that looks like this:
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
The GET filter is applied to get the value of the specified path 'make' from the 'car' object/variable.
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.
The GET filter allows for flexible default values.
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.
For this example, we will implement the path name "first.name" with the escape sequence.
We are able to use the escape sequence in the path to include a single dot in the path name.
The result is:
The escape sequence enables us to include the . in the path name
Last modified 10mo ago