I'm trying to filter by value an array in my Json with Jsonpath. I want to get the long_name of the country in the JSON below. In order to do that, I filter the adress_components by types[0] == "country" but it doesn't seem to work.
The JsonPath I tried :
$.results[0].address_components[?(@['types'][0]=="country")].long_name
The result I want is : "Canada".
The JSON :
{
"results" : [
{
"address_components" : [
{
"long_name" : "5510-5520",
"short_name" : "5510-5520",
"types" : [ "street_number" ]
},
{
"long_name" : "Yonge Street",
"short_name" : "Yonge St",
"types" : [ "route" ]
},
{
"long_name" : "Willowdale",
"short_name" : "Willowdale",
"types" : [ "neighborhood", "political" ]
},
{
"long_name" : "North York",
"short_name" : "North York",
"types" : [ "political", "sublocality", "sublocality_level_1" ]
},
{
"long_name" : "Toronto",
"short_name" : "Toronto",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Toronto Division",
"short_name" : "Toronto Division",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Ontario",
"short_name" : "ON",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Canada",
"short_name" : "CA",
"types" : [ "country", "political" ]
},
{
"long_name" : "M2N 5S3",
"short_name" : "M2N 5S3",
"types" : [ "postal_code" ]
}
]
}
],
"status" : "OK"
}
Thank you for your help.