I have a following response string from Google Geocoding API stored in a SQL Server database:
{
"results":[
{
"address_components":[
{
"long_name":"Khalifa City",
"short_name":"Khalifa City",
"types":[
"political",
"sublocality",
"sublocality_level_1"
]
},
{
"long_name":"Abu Dhabi",
"short_name":"Abu Dhabi",
"types":[
"locality",
"political"
]
},
{
"long_name":"Abu Dhabi",
"short_name":"Abu Dhabi",
"types":[
"administrative_area_level_1",
"political"
]
},
{
"long_name":"United Arab Emirates",
"short_name":"AE",
"types":[
"country",
"political"
]
}
],
...
}
],
"status":"OK"
}
My task is to extract Country and City from the above JSON. I checked the data and it seems that Geocoding API does not always return 4 elements in address_component node, so I need to get element in the array where types contain administrative_area_level_1 for the city, for example, which should logically be something like this:
JSON_QUERY([Json], '$.results[0].address_components<where types = administrative_area_level_1>.short_name')