0

The JSON looks like this:

"awards": [
   "awardsAtLevel": {
       "1": "Gold",
       "3": "Gold",
       "5": "Gold",
       "7": "Gold"
   }
]

so I'd assume I should just use the bracket syntax:

...awards.awardsAtLevel["1"]

But this doesn't get the data.

My full array looks like so:

{
   "data": [
      {
      "awards": [
            "awardsAtLevel": {
               "1": "Gold",
               ...
            }
         ]
      }
   ]
}

I've tried:

...awardsAtLevel["1"].text

as well, but this doesn't work either.

awards.awardsAtLevel 

does print the entire array.

The context is I'm getting data to make a b-table in bootstrap vue:

<template v-slot:cell(dmg)="rewards">
        {{rewards.item.awards.awardsAtLevel["1"] && rewards.item.awards.awardsAtLevel["1"] ? rewards.item.awards.awardsAtLevel["1"]: ""}}
</template>

Also, sorry if this is a common question. I couldn't find other questions where the bracket notation didn't work.

Nivyan
  • 119
  • 12

1 Answers1

0

Your JSON structure is invalid, it supposed to be

"awards": {
   "awardsAtLevel": {
       "1": "Gold",
       "3": "Gold",
       "5": "Gold",
       "7": "Gold"
   }
}

(using curly bracket, not squared)

And to show the data, you can do:

{{ awards.awardsAtLevel["1"] }}

Demo here

Owl
  • 6,337
  • 3
  • 16
  • 30