As a complete beginner in learning TypeScript, I am exploring how to parse JSON data on a web page and understand the underlying process. Despite searching extensively online, I have yet to find a solution.
Here is my current code:
var a = fetch("places.json")
.then(response => response.json())
.then(json => console.log("json"));
//The above line prints the JSON data to the console
Below is the content of places.json
{
"html_attributions" : [],
"results" : [
{
"formatted_address" : "123 Main St, Boston, MA 02110, USA",
"geometry" : {
"location" : {
"lat" : 42.3744875,
"lng" : -71.06347439999999
},
"viewport" : {
"northeast" : {
"lat" : 42.37581182989273,
"lng" : -71.06218627010728
},
"southwest" : {
"lat" : 42.37311217010728,
"lng" : -71.06488592989272
}
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
"id" : "4747c342bc144e98fba53bf2f41b6ed707e2fef0",
"name" : "123 Main St",
"place_id" : "ChIJd_ueCe1w44kRD_KFuN5w5nA",
"plus_code" : {
"compound_code" : "9WFP+QJ Boston, Massachusetts, United States",
"global_code" : "87JC9WFP+QJ"
},
"reference" : "ChIJd_ueCe1w44kRD_KFuN5w5nA",
"types" : [ "street_address" ]
}
],
"status" : "OK"
}