In the JSON example at the bottom of this question, how can I count the number of key / value pairs in an array "Tags"using JMESPath?
According to the JMESPath documentation , I can do this using a function count()-
For example, the following expression creates an array containing the total number of elements in the foo object, followed by the value foo ["bar"].
However, the documentation seems to be incorrect. Using the JMESPath website, the query Reservations[].Instances[].[count(@), Tags]returns a result [ [ null ] ]. Then I tested using the AWS command line and an error was returned -
Unknown function: count ()
Is there any way to do this using JMESPath?
JSON Example -
{
"Reservations": [
{
"Instances": [
{
"InstanceId": "i-asdf1234",
"InstanceName": "My Instance",
"Tags": [
{
"Value": "Value1",
"Key": "Key1"
},
{
"Value": "Value2",
"Key": "Key2"
},
{
"Value": "Value3",
"Key": "Key3"
},
{
"Value": "Value4",
"Key": "Key4"
}
]
}
]
}
]
}