I am trying to extract and print the postal_code value from the JSON file provided below:
{
"results" : [
{
"address_components" : [
{
"long_name" : "286",
"short_name" : "286",
"types" : [ "street_number" ]
},
{
"long_name" : "West El Camino Real",
"short_name" : "W El Camino Real",
"types" : [ "route" ]
},
{
"long_name" : "Old Mountain View",
"short_name" : "Old Mountain View",
"types" : [ "neighborhood", "political" ]
},
{
"long_name" : "Mountain View",
"short_name" : "Mountain View",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Santa Clara County",
"short_name" : "Santa Clara County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "California",
"short_name" : "CA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "94040",
"short_name" : "94040",
"types" : [ "postal_code" ]
},
{
"long_name" : "2606",
"short_name" : "2606",
"types" : [ "postal_code_suffix" ]
}
],
"formatted_address" : "286 W El Camino Real, Mountain View, CA 94040, USA",
"geometry" : {
"location" : {
"lat" : 37.3833211,
"lng" : -122.0782706
},
"location_type" : "ROOFTOP",
"viewport" : {
"northeast" : {
"lat" : 37.38467008029149,
"lng" : -122.0769216197085
},
"southwest" : {
"lat" : 37.3819721197085,
"lng" : -122.0796195802915
}
}
},
"place_id" : "ChIJieTN_yu3j4AR6cF-aEhdc58",
"types" : [ "street_address" ]
}
"status" : "OK"
}
Below is the code I have written to fetch and display the response:
$.ajax({
dataType: "json",
url: 'https://maps.googleapis.com/maps/api/geocode/json?latlng=37.383253,-122.078075&sensor=false',
data: latlog,
success: function (response) {
$("#response").html(JSON.stringify(response["results"], null, 4));
}
});
The current output displays the entire object. How can I specifically display only the postal_code value which is 94040?