I have a dynamically changing json array and I need to reference the array length using jmespath query. For example
{
"locations": [
{"name": "Seattle", "state": "WA"},
{"name": "New York", "state": "NY"},
{"name": "Bellevue", "state": "WA"},
{"name": "Olympia", "state": "WA"}
]
}
If I use jmespath query like length(locations), I get the desired result 4
and if I use locations[0], I get desired result { “name”: “Seattle”, “state”: “WA” }
but lets say I want to combine both the queries like locations[length(locations)] which should translate to locations[4] but this does not work at all. I tried many combinations to get the array length but this is not working. Can anyone help me here?
I need this because my json array length changes dynamically based on user interaction