Skip to content
Advertisement

Nested Arrays and returning non-labeled values

I’ve got an API that returns the following:

{
  "data": {
    "columns": [
      "epoch_timestamp_millieseconds", 
      "cpu_used_percent"
    ], 
    "values": [
      [
        1615230210000, 
        28.24
      ],
...

I’m able to get the second metric using the following three lines of code:

<#assign metricvalue = jsonObj.data.values[0]>
<#assign arr = metricvalue[1]>
&value=${arr}

&value would equal 28.24.

Is there a way to combine these into one line of code? I’m looking for something like this: &value=jsonObj.data.values[0].[1] The issue is the [1] doesn’t have a label

Advertisement

Answer

Your code is almost correct. Just a small correction. Remove the . between [0] and [1]. You don’t need to use . to specify the index. You only need to use it to specify the property/key.

The code should be like

jsonObj.data.values[0][0] // 1615230210000
jsonObj.data.values[0][1] // 28.24
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement