Access JSON array value with number name

1.2k Views Asked by At

We have the following JSON structure

enter image description here

I am trying to access data array values. I notice value names are numbers and somehow when trying to define the logic, they are not recognized. All the following had errors.

series[0].data[0].0
series[0].data[0].0[0]
series[0].data[0]."0"
series[0].data[0].'0'

The error message is "member '0' not found"

(swapping the last part of the logic, same error on every attempt)

Could you please help me figure out if there is a sytanx problem or something else?

This is the first part only non-processed dummy data

{
  "request": {
    "command": "dummy",
    "series_id": "dummy"
  },
  "series": [
    {
      "series_id": "dummy",
      "name": "dummy",
      "units": "dummy",
      "f": "W",
      "unitsshort": "dummy",
      "description": "dummy",
      "copyright": "dummy",
      "source": "dummy",
      "start": "19900406",
      "end": "20180803",
      "updated": "2018-08-08T14:01:44-0400",
      "data": [
        [
          "20180803",
          2.104
        ],
        [
          "20180727",
          2.11
        ],
        [
          "20180720",
          2.042
        ],
     ...

BTW, I am using IBM Workload Scheduler to access an API to retrieve this data. The tool framewrok let's me specify the JSON Properties I want to get from the results. If I try to get the whole first array value I succeed

series[0].data[0]

JSONResult:[20180803, 2.104]


UPDATE

Adding screens from IBM Workload Scheduler

enter image description here

enter image description here

1

There are 1 best solutions below

2
On

As was said in the comments, if you want to get the value 20180803 you should be using series[0].data[0][0]. Here is an example:

let theData = {
  "request": {
    "command": "dummy",
    "series_id": "dummy"
  },
  "series": [{
    "series_id": "dummy",
    "name": "dummy",
    "units": "dummy",
    "f": "W",
    "unitsshort": "dummy",
    "description": "dummy",
    "copyright": "dummy",
    "source": "dummy",
    "start": "19900406",
    "end": "20180803",
    "updated": "2018-08-08T14:01:44-0400",
    "data": [
      [
        "20180803",
        2.104
      ],
      [
        "20180727",
        2.11
      ],
      [
        "20180720",
        2.042
      ]
    ]
  }]
}

console.log(theData.series[0].data[0][0])