sorusty
sorusty

Reputation: 21

load json and show in #each block; Uncaught Error: {#each} only iterates over array-like objects

In Svelte (3) I'm loading JSON via the rollup json plugin and am trying to do a #each loop in the template

App.svelte

<script>
    import * as quests from './quests.json';
</script>

<main>
    <h1>DDO Hardcore Favor Planner</h1>
    {#each quests as quest}
        {quest.name}
    {/each}
</main>

I'm getting

Uncaught Error: {#each} only iterates over array-like objects.

example json excerpt

[
  {
    "name": "Violent Delights",
    "level": 1,
    "pack": "Keep on the Borderlands",
    "patron": "The Gatekeepers",
    "favor": 2
  },
  {
    "name": "The Hobgoblin Horde",
    "level": 1,
    "pack": "Keep on the Borderlands",
    "patron": "The Gatekeepers",
    "favor": 3
  }
]

Upvotes: 1

Views: 820

Answers (1)

sorusty
sorusty

Reputation: 21

The import was wrong

Instead of

import * as quests from './quests.json';

use

import quests from './quests.json';

Upvotes: 1

Related Questions