Hi there!
I have a HTTP request Node which queries Google Maps API and returns address data (example output below). I need to access the address_components fields so I can structure the address correctly in a database.
How can I run through this data, and output the long_names as values with the ‘types’ as the keys?
I’ve found a few scripts online that appear to do something similar (How to parse google maps Address components. (geocoder response) | by Ahmed Ali Thabet | Medium) and don’t think it can be that difficult but can’t for the life of me get them to work when I paste into a Function Node and attempt to access via items. Can anyone please help me?
[{
"plus_code": {
"compound_code": "Q2G3+XXP Selby, UK",
"global_code": "9C5XQ2G3+XXP"
},
"results": [{
"address_components": [{
"long_name": "5",
"short_name": "5",
"types": [
"street_number"
]
},
{
"long_name": "The Shrubberies",
"short_name": "The Shrubberies",
"types": [
"route"
]
},
{
"long_name": "Cliffe",
"short_name": "Cliffe",
"types": [
"locality",
"political"
]
},
{
"long_name": "Selby",
"short_name": "Selby",
"types": [
"postal_town"
]
},
{
"long_name": "North Yorkshire",
"short_name": "North Yorkshire",
"types": [
"administrative_area_level_2",
"political"
]
},
{
"long_name": "England",
"short_name": "England",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "United Kingdom",
"short_name": "GB",
"types": [
"country",
"political"
]
},
{
"long_name": "YO8 6PW",
"short_name": "YO8 6PW",
"types": [
"postal_code"
]
}
],
"formatted_address": "5 The Shrubberies, Cliffe, Selby YO8 6PW, UK",
"geometry": {
"bounds": {
"northeast": {
"lat": 53.7776495,
"lng": -0.9949507999999999
},
"southwest": {
"lat": 53.7775064,
"lng": -0.9951573
}
},
"location": {
"lat": 53.7775733,
"lng": -0.9950642999999999
},
"location_type": "ROOFTOP",
"viewport": {
"northeast": {
"lat": 53.7789269302915,
"lng": -0.9937050697084978
},
"southwest": {
"lat": 53.7762289697085,
"lng": -0.9964030302915019
}
}
},
"place_id": "ChIJ52OBwh0jeUgRAaAPAnafIZY",
"types": [
"premise"
]
},
{
"address_components": [{
"long_name": "8",
"short_name": "8",
"types": [
"street_number"
]
},
{
"long_name": "The Shrubberies",
"short_name": "The Shrubberies",
"types": [
"route"
]
},
{
"long_name": "Cliffe",
"short_name": "Cliffe",
"types": [
"locality",
"political"
]
},
{
"long_name": "Selby",
"short_name": "Selby",
"types": [
"postal_town"
]
},
{
"long_name": "North Yorkshire",
"short_name": "North Yorkshire",
"types": [
"administrative_area_level_2",
"political"
]
},
{
"long_name": "England",
"short_name": "England",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "United Kingdom",
"short_name": "GB",
"types": [
"country",
"political"
]
},
{
"long_name": "YO8 6PW",
"short_name": "YO8 6PW",
"types": [
"postal_code"
]
}
],
"formatted_address": "8 The Shrubberies, Cliffe, Selby YO8 6PW, UK",
"geometry": {
"location": {
"lat": 53.7775616,
"lng": -0.9949786
},
"location_type": "ROOFTOP",
"viewport": {
"northeast": {
"lat": 53.7789105802915,
"lng": -0.993629619708498
},
"southwest": {
"lat": 53.7762126197085,
"lng": -0.996327580291502
}
}
},
"place_id": "ChIJV9Be2h0jeUgRZMzUX0q07ME",
"plus_code": {
"compound_code": "Q2H4+22 Selby, UK",
"global_code": "9C5XQ2H4+22"
},
"types": [
"street_address"
]
},
{
"address_components": [{
"long_name": "The Shrubberies",
"short_name": "The Shrubberies",
"types": [
"establishment",
"point_of_interest",
"transit_station"
]
},
{
"long_name": "Cliffe",
"short_name": "Cliffe",
"types": [
"locality",
"political"
]
},
{
"long_name": "Selby",
"short_name": "Selby",
"types": [
"postal_town"
]
},
{
"long_name": "North Yorkshire",
"short_name": "North Yorkshire",
"types": [
"administrative_area_level_2",
"political"
]
},
{
"long_name": "England",
"short_name": "England",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "United Kingdom",
"short_name": "GB",
"types": [
"country",
"political"
]
},
{
"long_name": "YO8 6NH",
"short_name": "YO8 6NH",
"types": [
"postal_code"
]
}
],
"formatted_address": "The Shrubberies, Cliffe, Selby YO8 6NH, UK",
"geometry": {
"location": {
"lat": 53.777054,
"lng": -0.994312
},
"location_type": "GEOMETRIC_CENTER",
"viewport": {
"northeast": {
"lat": 53.7784029802915,
"lng": -0.9929630197084979
},
"southwest": {
"lat": 53.7757050197085,
"lng": -0.995660980291502
}
}
},
"place_id": "ChIJzx4gkx0jeUgRfAYg3nLwVJc",
"plus_code": {
"compound_code": "Q2G4+R7 Selby, UK",
"global_code": "9C5XQ2G4+R7"
},
"types": [
"establishment",
"point_of_interest",
"transit_station"
]
},
{
"address_components": [{
"long_name": "Q2G3+XX",
"short_name": "Q2G3+XX",
"types": [
"plus_code"
]
},
{
"long_name": "Selby",
"short_name": "Selby",
"types": [
"postal_town"
]
},
{
"long_name": "England",
"short_name": "England",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "United Kingdom",
"short_name": "GB",
"types": [
"country",
"political"
]
}
],
"formatted_address": "Q2G3+XX Selby, UK",
"geometry": {
"bounds": {
"northeast": {
"lat": 53.7775,
"lng": -0.9949999999999999
},
"southwest": {
"lat": 53.777375,
"lng": -0.995125
}
},
"location": {
"lat": 53.77745900000001,
"lng": -0.995035
},
"location_type": "GEOMETRIC_CENTER",
"viewport": {
"northeast": {
"lat": 53.77878648029149,
"lng": -0.993713519708498
},
"southwest": {
"lat": 53.77608851970849,
"lng": -0.9964114802915021
}
}
},
"place_id": "GhIJjn3JxoPjSkAR8wLso1PX778",
"plus_code": {
"compound_code": "Q2G3+XX Selby, UK",
"global_code": "9C5XQ2G3+XX"
},
"types": [
"plus_code"
]
},
{
"address_components": [{
"long_name": "1-38",
"short_name": "1-38",
"types": [
"street_number"
]
},
{
"long_name": "The Shrubberies",
"short_name": "The Shrubberies",
"types": [
"route"
]
},
{
"long_name": "Cliffe",
"short_name": "Cliffe",
"types": [
"locality",
"political"
]
},
{
"long_name": "Selby",
"short_name": "Selby",
"types": [
"postal_town"
]
},
{
"long_name": "North Yorkshire",
"short_name": "North Yorkshire",
"types": [
"administrative_area_level_2",
"political"
]
},
{
"long_name": "England",
"short_name": "England",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "United Kingdom",
"short_name": "GB",
"types": [
"country",
"political"
]
},
{
"long_name": "YO8",
"short_name": "YO8",
"types": [
"postal_code",
"postal_code_prefix"
]
}
],
"formatted_address": "1-38 The Shrubberies, Cliffe, Selby YO8, UK",
"geometry": {
"bounds": {
"northeast": {
"lat": 53.77829819999999,
"lng": -0.9947021999999999
},
"southwest": {
"lat": 53.7770666,
"lng": -0.9961247000000001
}
},
"location": {
"lat": 53.7780139,
"lng": -0.9948007
},
"location_type": "GEOMETRIC_CENTER",
"viewport": {
"northeast": {
"lat": 53.7790313802915,
"lng": -0.9940644697084979
},
"southwest": {
"lat": 53.7763334197085,
"lng": -0.996762430291502
}
}
},
"place_id": "ChIJK6MF3R0jeUgRgBN8BloTElQ",
"types": [
"route"
]
},
{
"address_components": [{
"long_name": "YO8 6PW",
"short_name": "YO8 6PW",
"types": [
"postal_code"
]
},
{
"long_name": "The Shrubberies",
"short_name": "The Shrubberies",
"types": [
"route"
]
},
{
"long_name": "Cliffe",
"short_name": "Cliffe",
"types": [
"locality",
"political"
]
},
{
"long_name": "Selby",
"short_name": "Selby",
"types": [
"postal_town"
]
},
{
"long_name": "North Yorkshire",
"short_name": "North Yorkshire",
"types": [
"administrative_area_level_2",
"political"
]
},
{
"long_name": "England",
"short_name": "England",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "United Kingdom",
"short_name": "GB",
"types": [
"country",
"political"
]
}
],
"formatted_address": "The Shrubberies, Cliffe, Selby YO8 6PW, UK",
"geometry": {
"bounds": {
"northeast": {
"lat": 53.7800042,
"lng": -0.9946520999999999
},
"southwest": {
"lat": 53.7766193,
"lng": -0.9963685999999999
}
},
"location": {
"lat": 53.7781428,
"lng": -0.9954843000000001
},
"location_type": "APPROXIMATE",
"viewport": {
"northeast": {
"lat": 53.7800042,
"lng": -0.9941613697084978
},
"southwest": {
"lat": 53.7766193,
"lng": -0.9968593302915019
}
}
},
"place_id": "ChIJrRz22h0jeUgRbnV5W211As4",
"types": [
"postal_code"
]
},
{
"address_components": [{
"long_name": "Cliffe",
"short_name": "Cliffe",
"types": [
"locality",
"political"
]
},
{
"long_name": "Selby",
"short_name": "Selby",
"types": [
"postal_town"
]
},
{
"long_name": "North Yorkshire",
"short_name": "North Yorkshire",
"types": [
"administrative_area_level_2",
"political"
]
},
{
"long_name": "England",
"short_name": "England",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "United Kingdom",
"short_name": "GB",
"types": [
"country",
"political"
]
},
{
"long_name": "YO8",
"short_name": "YO8",
"types": [
"postal_code",
"postal_code_prefix"
]
}
],
"formatted_address": "Cliffe, Selby YO8, UK",
"geometry": {
"bounds": {
"northeast": {
"lat": 53.7899617,
"lng": -0.9883202
},
"southwest": {
"lat": 53.774036,
"lng": -1.0044702
}
},
"location": {
"lat": 53.7800142,
"lng": -0.9971095000000001
},
"location_type": "APPROXIMATE",
"viewport": {
"northeast": {
"lat": 53.7899617,
"lng": -0.9883202
},
"southwest": {
"lat": 53.774036,
"lng": -1.0044702
}
}
},
"place_id": "ChIJ_5S7aicjeUgRtMVpoiaR8qE",
"types": [
"locality",
"political"
]
},
{
"address_components": [{
"long_name": "Cliffe",
"short_name": "Cliffe",
"types": [
"administrative_area_level_4",
"political"
]
},
{
"long_name": "Selby",
"short_name": "Selby",
"types": [
"postal_town"
]
},
{
"long_name": "North Yorkshire",
"short_name": "North Yorkshire",
"types": [
"administrative_area_level_2",
"political"
]
},
{
"long_name": "England",
"short_name": "England",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "United Kingdom",
"short_name": "GB",
"types": [
"country",
"political"
]
},
{
"long_name": "YO8",
"short_name": "YO8",
"types": [
"postal_code",
"postal_code_prefix"
]
}
],
"formatted_address": "Cliffe, Selby YO8, UK",
"geometry": {
"bounds": {
"northeast": {
"lat": 53.8218872,
"lng": -0.9341634999999999
},
"southwest": {
"lat": 53.7598041,
"lng": -1.0365264
}
},
"location": {
"lat": 53.7925714,
"lng": -0.9836201000000001
},
"location_type": "APPROXIMATE",
"viewport": {
"northeast": {
"lat": 53.8218872,
"lng": -0.9341634999999999
},
"southwest": {
"lat": 53.7598041,
"lng": -1.0365264
}
}
},
"place_id": "ChIJY4aH6Q4jeUgR0B9t7Z75DAU",
"types": [
"administrative_area_level_4",
"political"
]
},
{
"address_components": [{
"long_name": "YO8",
"short_name": "YO8",
"types": [
"postal_code",
"postal_code_prefix"
]
},
{
"long_name": "Selby",
"short_name": "Selby",
"types": [
"postal_town"
]
},
{
"long_name": "England",
"short_name": "England",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "United Kingdom",
"short_name": "GB",
"types": [
"country",
"political"
]
}
],
"formatted_address": "Selby YO8, UK",
"geometry": {
"bounds": {
"northeast": {
"lat": 53.8620955,
"lng": -0.8143208
},
"southwest": {
"lat": 53.700854,
"lng": -1.1939887
}
},
"location": {
"lat": 53.7978369,
"lng": -1.0032842
},
"location_type": "APPROXIMATE",
"viewport": {
"northeast": {
"lat": 53.8620955,
"lng": -0.8143208
},
"southwest": {
"lat": 53.700854,
"lng": -1.1939887
}
}
},
"place_id": "ChIJj20O6gEWeUgR1phll-wRyls",
"types": [
"postal_code",
"postal_code_prefix"
]
},
{
"address_components": [{
"long_name": "Selby",
"short_name": "Selby",
"types": [
"postal_town"
]
},
{
"long_name": "England",
"short_name": "England",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "United Kingdom",
"short_name": "GB",
"types": [
"country",
"political"
]
}
],
"formatted_address": "Selby, UK",
"geometry": {
"bounds": {
"northeast": {
"lat": 53.85938239999999,
"lng": -0.8253381
},
"southwest": {
"lat": 53.7009007,
"lng": -1.1955835
}
},
"location": {
"lat": 53.7978369,
"lng": -1.0032842
},
"location_type": "APPROXIMATE",
"viewport": {
"northeast": {
"lat": 53.85938239999999,
"lng": -0.8253381
},
"southwest": {
"lat": 53.7009007,
"lng": -1.1955835
}
}
},
"place_id": "ChIJW-phvyYjeUgRp4YN5SPtn3M",
"types": [
"postal_town"
]
},
{
"address_components": [{
"long_name": "Selby",
"short_name": "Selby",
"types": [
"administrative_area_level_3",
"political"
]
},
{
"long_name": "North Yorkshire",
"short_name": "North Yorkshire",
"types": [
"administrative_area_level_2",
"political"
]
},
{
"long_name": "England",
"short_name": "England",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "United Kingdom",
"short_name": "GB",
"types": [
"country",
"political"
]
}
],
"formatted_address": "Selby, UK",
"geometry": {
"bounds": {
"northeast": {
"lat": 53.935584,
"lng": -0.9034008
},
"southwest": {
"lat": 53.6210943,
"lng": -1.3529652
}
},
"location": {
"lat": 53.7867568,
"lng": -1.0677977
},
"location_type": "APPROXIMATE",
"viewport": {
"northeast": {
"lat": 53.935584,
"lng": -0.9034008
},
"southwest": {
"lat": 53.6210943,
"lng": -1.3529652
}
}
},
"place_id": "ChIJRzjbpCs8eUgRQONs7Z75DAQ",
"types": [
"administrative_area_level_3",
"political"
]
},
{
"address_components": [{
"long_name": "North Yorkshire",
"short_name": "North Yorkshire",
"types": [
"administrative_area_level_2",
"political"
]
},
{
"long_name": "England",
"short_name": "England",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "United Kingdom",
"short_name": "GB",
"types": [
"country",
"political"
]
}
],
"formatted_address": "North Yorkshire, UK",
"geometry": {
"bounds": {
"northeast": {
"lat": 54.56214379999999,
"lng": -0.2123533
},
"southwest": {
"lat": 53.6210943,
"lng": -2.5647389
}
},
"location": {
"lat": 53.9915028,
"lng": -1.5412015
},
"location_type": "APPROXIMATE",
"viewport": {
"northeast": {
"lat": 54.56214379999999,
"lng": -0.2123533
},
"southwest": {
"lat": 53.6210943,
"lng": -2.5647389
}
}
},
"place_id": "ChIJ8WWY4UDDeEgRt5-VyBki4MM",
"types": [
"administrative_area_level_2",
"political"
]
},
{
"address_components": [{
"long_name": "England",
"short_name": "England",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "United Kingdom",
"short_name": "GB",
"types": [
"country",
"political"
]
}
],
"formatted_address": "England, UK",
"geometry": {
"bounds": {
"northeast": {
"lat": 55.81165979999999,
"lng": 1.7629159
},
"southwest": {
"lat": 49.8647411,
"lng": -6.4185458
}
},
"location": {
"lat": 52.3555177,
"lng": -1.1743197
},
"location_type": "APPROXIMATE",
"viewport": {
"northeast": {
"lat": 55.81165979999999,
"lng": 1.7629159
},
"southwest": {
"lat": 49.8647411,
"lng": -6.4185458
}
}
},
"place_id": "ChIJ39UebIqp0EcRqI4tMyWV4fQ",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"address_components": [{
"long_name": "United Kingdom",
"short_name": "GB",
"types": [
"country",
"political"
]
}],
"formatted_address": "United Kingdom",
"geometry": {
"bounds": {
"northeast": {
"lat": 60.91569999999999,
"lng": 33.9165549
},
"southwest": {
"lat": 34.5614,
"lng": -8.8988999
}
},
"location": {
"lat": 55.378051,
"lng": -3.435973
},
"location_type": "APPROXIMATE",
"viewport": {
"northeast": {
"lat": 60.91569999999999,
"lng": 33.9165549
},
"southwest": {
"lat": 34.5614,
"lng": -8.8988999
}
}
},
"place_id": "ChIJqZHHQhE7WgIReiWIMkOg-MQ",
"types": [
"country",
"political"
]
}
],
"status": "OK"
}]