> For the complete documentation index, see [llms.txt](https://demirels-organization.gitbook.io/javascript-tutorial/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://demirels-organization.gitbook.io/javascript-tutorial/json-example-for-a-game/fetching-json-game-data.md).

# Fetching JSON game data

Here is an example of how you could use the `fetch` function to retrieve data from <https://6away.org/data.json> API and log the enemies:

```javascript
async function getEnemies() {
  const response = await fetch('https://6away.org/adventure.json');
  const data = await response.json();

  for (const enemy of data.enemies) {
    console.log(enemy);
  }
}

getEnemies();
```

This code makes an HTTP GET request to the `https://6away.org/adventure.json` API, which returns a JSON object containing data for a role-playing adventure game. The object is then parsed and the `enemies` array is logged to the console.

You can also use the `.then()` method to handle the response, like this:

```javascript
fetch('https://6away.org/adventure.json')
  .then(response => response.json())
  .then(data => {
    for (const enemy of data.enemies) {
      console.log(enemy);
    }
  });
```
