Dot Notation

Access properties of an object using dot notation

Sometimes you want to access a specific field or value in an object you might be returning.

Let's use an example where we're returning the variable cars from an API endpoint that has an array of two specific cars.

Let's say we ONLY wanted to return the first object's color. Which would be Red since the first car is Honda and the color is red.

[
{
"id": 1,
"created_at": 1622488736526,
"make": "Honda",
"color": "red",
"year": "1981"
},
{
"id": 2,
"created_at": 1622488742502,
"make": "Toyota",
"color": "blue",
"year": "2001"
}
]

Xano makes this really simple. We would first select the item being returned in the Response block.

We would then change the return to

cars.0.color

And we can change the as to anything we want. I will call it hondacolor

Now

After I save the response, I can simply hit Run & Debug again and see that i'm getting a return that looks like this:

Let's say I wanted JUST the colors of the entire array to be returned. I would just change the return to be (make sure the type is a variable)!

cars.color

And my response would look like this:

As you can see, dot notation is a very powerful tool to dive into an object and access EXACTLY the data you're looking for. Need more help on this topic? Feel free to post in our community!