Chapter projects
Working with JSON
Create a JSON file locally, connect to the JSON and data, and output the data from the JSON file into your console:
- Create a file with the extension JSON name it
people.json
. - Within
people.json
create an array that contains multiple objects. Each item in the array should be an object that has the same structure, usingfirst
,last
, andtopic
as the property names. Make sure you use double quotes around the property names and values as this is the proper JSON syntax. - Add three or more entries into the array using the same object structure for each item.
- Create an HTML file and add a JavaScript file. Within the JavaScript file use
people.json
as the URL. Usingfetch
connect to the URL and retrieve the data. Since this is a JSON-formatted file, once you get the response data it can be formatted into JSON using the.json()
method infetch
. - Output the full contents of the data into the console.
- Using
foreach...