How to access 2nd object in a json file?

Here is my json data

    {
       "id": 1,
  	   "name": "Flu",
       "category": 1,
       "lethality": 10,
       "curability": 80
    },
    {
       "id": 2,
  	   "name": "Stomach Cancer",
       "category": 2,
       "lethality": 50,
       "curability": 10
    }

I am trying to grab the values of the name value in position 2.

I am using diseaseTable = loadsave.loadTable( “diseases.json” ) to load my table.

When I use print( diseaseTable.name ) it will print out Flu. If i try to use print( diseaseTable[1].name ) or similar variations it would error out. Am I formatting my json wrong? Or am I referencing the json wrong?

If that is your JSON, then it’s incorrectly formatted and that’s most likely the reason it isn’t working as intended. Just add your data within square brackets and it should work, i.e.

[
{
   "id": 1,
   "name": "Flu",
   "category": 1,
   "lethality": 10,
   "curability": 80
},
{
   "id": 2,
   "name": "Stomach Cancer",
   "category": 2,
   "lethality": 50,
   "curability": 10
}
]
1 Like