I am trying to read some values from a JSON object and use them to populate an html template. I can seem to figure out the right syntax to read from the JSON file. For example, when I want to read in the first object's "role", I write:
console.log("first object: "+ ((obj[0].roles)[0]).name)
The above works and returns "first object: thing commented on".
Then when I try to read the text of the verb under the "srcLanguageSentence" within the first object, I write:
console.log("first verb: "+ ((obj[0].srcLanguageSentence.verb[2]).text)
I expect to see "first verb: comment" but that does not happen. Where is my syntax wrong here?Please see a snippet of the JSON object file below:
[
  {
    "description": "",
    "roles": [
      {
        "name": "thing commented on"
      },
      {
        "name": "commentor"
      }
    ],
    "srcLanguageSentence": {
      "roles": [
        {
          "beginOffset": 23,
          "endOffset": 30,
          "name": "thing commented on",
          "text": "on them"
        },
        {
          "beginOffset": 5,
          "endOffset": 7,
          "name": "commentor",
          "text": "We"
        }
      ],
      "text": "  `` We wo n't comment on them . '' ",
      "verb": {
        "beginOffset": 15,
        "endOffset": 22,
        "text": "comment"
      }
    },
    "tgtLanguageSentences": [
      {
        "roles": [
          {
            "beginOffset": 1,
            "endOffset": 31,
            "name": "thing commented on",
            "text": "Weitere Aspekte der Kommission"
          },
          {
            "beginOffset": 44,
            "endOffset": 47,
            "name": "commentor",
            "text": "ich"
          },
          {
            "beginOffset": 48,
            "endOffset": 55,
            "name": "negation",
            "text": "nicht ."
          }
        ],
        "text": "  Weitere Aspekte der Kommission kommentiere ich nicht . ",
        "verb": {
          "beginOffset": -1,
          "endOffset": -1,
          "sense": "COMMENT, intransitive",
          "text": "kommentieren"
        }
      }
    ],
    "verb": "KOMMENTIEREN"
  },
]
 
     
     
    